From: michele Date: 2006-10-25T01:10:15+09:00 Subject: Re: What's the difference between send and instance_eval? So there is no need for "send"? Thanks On Oct 24, 12:54 am, "Tim Pease" wrote: > On 10/23/06, michele wrote: > > > What's the difference between send and instance_eval (except the > > obvious syntax)? > > > I've been trying to figure out why Ruby has them both. It seems you can > > use them intechangeably, at least in the cases I've found and tested > > (so the question is if there is a case where can't change one for the > > other). > > > Sorry if this has been answered already. I really tried to find the > > answers in my Ruby and Rails books and on the Internet before posting > > the question here.send can only be used to execute existing methods on objects. > > instance_eval allows you to do much more -- i.e. adding instance > variables, tinkering with private methods, etc > > ary = %w( 1 2 3 4 ) > > ary.send :length #=> 4 > > ary.instance_eval do > @length = self.length > end > > ary.instance_variable_get :@length #=> 4 > > It's a dumb example, but it should convery the differences. > > Blessings, > TwP