I am trying to create a program that will execute one of several commands, depending on which one I enter, but it's not working. Here is an extremely simple print example that I am using for illustration purposes only. I know that I can print another way, I am just using this as an example. I don't want to use hashs or arrays because some of the commands may be quite lengthy.
#***************************************
def dog
puts 'I am a dog.'
end
def cat
puts 'I am a cat.'
end
puts 'Enter command: '
command_in = gets.chomp.downcase
command_in
puts 'Command ' + command_in + " executed.'
#***************************************
Here is what my output looks like...
Enter command:
(I enter "dog" as the response)
Command dog executed.
Here is what I want my output to look like...
Enter command:
(I enter "dog" as the response)
I am a dog.
Command dog executed.
How can I get the program to actually do command_in instead of treating it as a literal? I think I may have to create a proc or something, but I don't know how to do it.





Bookmarks