From: James Coglan Date: 2009-06-01T17:46:18+09:00 Subject: Re: eval? instance_eval?? hmm --001636c5a4357b6645046b457598 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 2009/6/1 Steve Hull > Hey ruby wizards. I got a question for you. I want to call a method on > my object instance, with the method name specified by a string. I want > to *pass in* a hash to my method. > > I tried: > > myMethodName = "doSomeStuff" > myObject.instance_eval "#{myMethodName}(#{myHash})" > > But it complained that it didn't have a method named #{myHash.to_s}. > > So I tried myObject.instance_eval { myMethodName(myHash) } > > But it compalined that it didn't have a method named "myMethodName" > (which is obvious -- the method I wanted to call is doSomeStuff). > > I'm new to metaprogramming in ruby. What am I missing here? myObject.__send__(myMethodName, myHash) is a more appropriate idiom for what you seem to be doing. --001636c5a4357b6645046b457598--