A
Alex Stahl
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']}")
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?
Thanks,
Alex
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']}")
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?
Thanks,
Alex