From: Robert Klemme Date: 2005-09-28T16:36:43+09:00 Subject: Re: Object private methods daz wrote: > Paolino wrote: >> Hello >> >> I noticed that Object private methods are available everywhere. >> This I noticed exploring 'main' instance defining a method >> >> Can I have some explanation on this form of globalizing ? >> > > > It's useful to have some methods available almost anywhere ... > > $_ = 'A B C' > puts split # there are two of the private methods > #-> A > #-> B > #-> C > > ... but not *everywhere* ... > > puts 3.split > > #-> ... private method `split' called for 3:Fixnum (NoMethodError) > > There is no 'split' method for Fixnum. Not exactly: Fixnum inherits split from Kernel and it's just not accessible with a receiver because it's private: 09:24:18 [Oracle]: ruby -e '$_="a,b,c"; p 1.instance_eval { split(/,/) }; p 1.send(:split, /,/)' ["a", "b", "c"] ["a", "b", "c"] > Fixnum inherits from Object and a 'split' was found but, fortunately, > a sensible error message was produced before disaster struck. Well you could argue about the sensibility (?) of the error message. Privacy is just a means to make it *look* like a global function. Kind regards robert