I’m trying to evaluate something like this but more complex, but I get a TypeError because apparently you can’t convert a hash to a string. Without changing my entire script, is there a decent workaround for this already ugly workaround?
hash = { :somestuff => "etc", ... }
eval module + "::" + object + "." + function + "(" + hash + ")"
Just an example of what I’m trying to do.
Thanks!
Well, stating that
module,objectand function are strings, I think a better way to do this would be:Kernel.const_getwill give you any constant (in this case a constant with the module instance) and it will put it on themodule_klassvariable. This will be the same as doingeval(module)but less expensive.To get classes or modules declared inside this
module_klassyou need to invokeconst_geton this instance, once you got that, you just use thesendmethod, this will call the methods you specify in the first parameter, and will pass to this functions the following parameters that are given.If for any reason this is not working for you, your solution might work if you just do:
But IMO that’s not as elegant and also is likely to be a slower implementation.
Hope that helps.