From: Andraes Tsepesh Date: 2010-06-26T12:30:50+09:00 Subject: Re: Use a string as a method call Chris Bailey wrote: > I then would like to search the commands hash for a key that matches the > player input and execute the method associated with that key. What I've > noticed is that upon initialization of the hash the value becomes equal > to the result of the method but that is not what I want. If I store the > value as a string ie "do_foo()" would I be able to parse that string and > execute it as a method? And if so, how would that be done? First time poster, and I was so surprised I was able to find this online. I've been working on figuring this out for hours. I've adopted the "send(value)" solution and it works great. My question is, how can I pass arguments to methods called this way? My hash is pretty much identical, here's a sample: commands = {"look" => "doLook"} I have split the input variable so I can accept more than 1 word at a time (input can be anything from ["look"] to ["look", "at", "the", "desk"]). I'd like to be able to pass the input variable to these methods, but am having difficulty with that. I have tried modifying my hash as so: commands = {"look" => "doLook(input)"} with no luck. I've also modified my send as so: send(commands[x](input)) with no luck. Any ideas? Thanks a bunch for any assistance anyone can provide :) -- Posted via http://www.ruby-forum.com/.