Morton Goldberg
2/20/2007 2:11:00 AM
On Feb 19, 2007, at 8:10 PM, kenbo wrote:
> Thanks for the folks that mentioned eval---I thought of that after the
> posting but assumed that, as in LISP, there might be a better way
> to accomplish
> it :-)
>
> It's nice to see more similarities between LISP and Ruby.
I don't know whether or not you will think this better than using
'eval', but in Ruby this kind of indirect reference problem can often
be handled by introducing a hash. For example,
<code>
a = %w{ one two three four five }
b = %w{ six seven eight nine }
h = {}
h['a'] = a
h['b'] = b
foo = 'a'
h[foo][2] # => "three"
foo = 'b'
h[foo][2] # => "eight"
</code>
Regards, Morton