From: Josh Cheek Date: 2010-07-13T03:30:32+09:00 Subject: Re: How to pass a hash as a param to a method called through eval? --0016e6d64717066eff048b34f2f0 Content-Type: text/plain; charset=ISO-8859-1 Eval is also a wonky work flow. You have data serialized as JSON in a String You parse it into a Ruby hash You then serialize it as Ruby code in a String You then eval the string to get the hash back out of it... I don't know what types JSON supports, but if it supports anything that doesn't have a literal, then that second converting to String and evaling will break. Also explains why Amir's solution breaks on 1.8, because, as David A. Black pointed out, Hash#to_s changed, and that is what is being used to serialize it (which implies to me that this may not be realized) mini:~ ammar$ rvm use 1.9.1 info: Using ruby 1.9.1 p378 mini:~ ammar$ irb ruby-1.9.1-p378 > require 'json' => true ruby-1.9.1-p378 > def some_func(hash); puts "from function: #{hash.inspect}"; end => nil ruby-1.9.1-p378 > j = '{ "action": "some_func", "params": { "a": "foo", "b": "bar" } }' => "{ \"action\": \"some_func\", \"params\": { \"a\": \"foo\", \"b\": \"bar\" } }" ruby-1.9.1-p378 > call = JSON.parse(j) => {"action"=>"some_func", "params"=>{"a"=>"foo", "b"=>"bar"}} ruby-1.9.1-p378 > eval("#{call['action']}(#{ call['params']})") from function: {"a"=>"foo", "b"=>"bar"} => nil --0016e6d64717066eff048b34f2f0--