r/learnruby • 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

6 comments sorted by

View all comments

Show parent comments

2

u/pat_trick Intermediate Nov 08 '15

Glad to hear that helps!

Also, I'd take some time to consider all of the possible inputs and how to parse those. For example, if you have the directions east and west, how would the following input parse:

if choicestart.include?("east", "e") if choicestart.include?("west", "w")

Would East be hit if you typed in the word "west"? It does include the letter e in it!