From: Alex Stahl Date: 2010-07-12T06:41:04+09:00 Subject: Re: How to pass a hash as a param to a method called through eval? Thanks. You're actually the second response to suggest doing it that way (w/ eval). But it doesn't work for me. Though, the first respondent is using 1.9.1, and I've got 1.8.7 at the moment. Are you by chance also on 1.9.1? -Alex On Sun, 2010-07-11 at 16:05 -0500, yermej wrote: > On Jul 11, 2:57 pm, Alex Stahl wrote: > [...] > > Problem is that 'call['params']' is treated as a string by the receiver, > > not the hash I intended to pass. Tried using casting operations first, > > like .to_s and then .to_hash, but the to_hash call fails w/ no method > > error. Instead the hash comes through as a string. How can I pass it > > so that it remains a hash, and retains its structure for key/val reading > > in the receiver? > > > > This will do it: > > eval("#{call['action']}(call['params'])") > > Depending on context, you can probably completely avoid using eval: > > method(call['action']).call(call['params']) > > When you use #{call['params']}, I think that calls #to_s on the Hash > which causes what you're seeing. > > Jeremy >