In Ruby, you can easily access local variables programmatically by using local_variables
and eval
. I would really like to have meta-programming acc
It's a shame there isn't a built-in way to get the caller's binding. The block trick seems to be the usual answer to this question.
However there is another 'trick' which existed for older 1.8 Ruby versions called binding_of_caller
. Looks like quix ported it to 1.9. You might want to check that out:
https://github.com/quix/binding_of_caller