Joel VanderWerf
10/26/2006 5:47:00 PM
Rick DeNatale wrote:
> On 10/26/06, Joel VanderWerf <vjoel@path.berkeley.edu> wrote:
>
>> That's true, but only because I chose a bad example. Here's a better one:
>>
>> h = {1=>2}
>> msg = [:concat, [4, 5, 6, IO, String, Kernel, h]]
>> a = [1,2,3]
>> p a.send(*msg) # ==> [1, 2, 3, 4, 5, 6, IO, String, Kernel, {1=>2}]
>> p a.instance_eval(msg.to_s) # ==> NameError
>>
>> To make the instance_eval work here, you would have to find a way to
>> turn the argument array into a string that, when eval-ed, is that same
>> array. (It's possible, but painful, and you lose the identity of the
>> hash h.)
>
> except that instance_eval can take a block in lieu of a string:
>
> a.instance_eval {concat [1,2,3,4,5,6,IO,String,Kernel, h]}
> => [1, 2, 3, 1, 2, 3, 4, 5, 6, IO, String, Kernel, {1=>2}]
>
> Not that I think that send should be eliminated, both methods are
> useful. Horses for courses.
And I'm starting to beat a dead horse here, but using a block leads you
to scoping issues. (What if the hash were @h or a method call instead of
h? You can always use an temporary local var to avoid the issue.)
You're quite right: each method has its place.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407