From: Brian Candler Date: 2010-07-12T05:47:10+09:00 Subject: Re: How to pass a hash as a param to a method called through eval? Alex Stahl wrote: > Hi Folks - I've got a data-driven app I'm building, and I'd like to be > able to read a set of data from a json file, pass that to eval, and have > it executed: > > json: > { > "action": "someFunc", > "params": { > "a": "foo", > "b": "bar", > "c": "etc" > } > } > > call = JSON.parse(json) > eval("#{call['action']} #{call['params']}") I'm pretty sure that what you really want is this: send(call['action'], call['params']) For simple cases you might be able to work with eval, like this: eval("#{call['action']} #{call['params'].inspect}") But that's fragile, slow, and fraught with security dangers. If what you want is to call a method whose name is in a variable, then the tool is provided to do that: 'send' -- Posted via http://www.ruby-forum.com/.