From: Neil Mc Laughlin Date: 2004-06-14T22:36:10+09:00 Subject: Re: method_missing and send Thanks for that. I see that send does indeed call the private method. I'm still a bit puzzled as to why 'obj.send(:msg)' should behave differently from 'obj.msg'. My impression was that they are different ways of expressing the same concept - sending a message to an object. That's why I expected the same result from either call. Does anyone else think this odd or even in violation of the principle of least surprise? Regards, Neil ----- Original Message ----- From: "ts" To: "ruby-talk ML" Cc: Sent: Monday, June 14, 2004 12:25 PM Subject: Re: method_missing and send > >>>>> "N" == Neil Mc Laughlin writes: > > N> Is this a bug in ruby or have I missed something? > > #warn is a private method of Kernel > > When you call it, like a public method (i.e. B.warn), ruby don't find it > and call #method_missing > > With #send ruby is able to find any methods (even private) and call it. > > For example > > svg% cat b.rb > #!/usr/bin/ruby > class A > class << self > def method_missing(*args) > puts "method_missing : #{args}" > end > > private > def tt(*args) > puts "tt : #{args}" > end > end > end > > A.tt(1, 2) > A.send(:tt, 3, 4) > svg% > > svg% b.rb > method_missing : tt12 > tt : 34 > svg% > > > Guy Decoux > > > > >