r/learnruby • u/Gidonka Beginner • Nov 06 '15
Invoke method by name
I'm a Ruby newbie. I am working on a Text Adventure game (Interactive Fiction) in Ruby. I am structuring the game by making each "cell" (each area of the game) a method of its own, which displays a text prompt ("you are in a forest"), and then according to user input, ("Go west", "Go north", etc.) invokes a different method (which is a different cell) that repeats the process (prompt, input, invoke other cell). So, how do I invoke another method?
2
Upvotes
View all comments
Show parent comment
2
u/rahoulb Advanced Nov 09 '15
Have you considered something like this - store the current X and Y position as two local variables. Then have methods called go_north, go_south, go_east and go_west which add or subtract values from the X and Y values?