From: Joel VanderWerf Date: 2006-10-26T15:53:30+09:00 Subject: Re: What's the difference between send and instance_eval? Putting the comments in order... > Joel VanderWerf wrote: >> Another case, showing the real point of #send: >> >> msg = :reverse >> a = [1,2,3] >> b = a.send msg >> p b >> >> __END__ >> >> Output: >> >> [3, 2, 1] >> >> There's no easy equivalent with #instance_evaland blocks (you could >> mess with strings, though). michele wrote: > This works: > > msg = :reverse > a = [1,2,3] > a.instance_eval(msg.to_s) 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.) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407