From: matt@... (matt neuburg) Date: 2006-10-28T04:05:15+09:00 Subject: Re: classless methods Hugh Sasse wrote: > On Sat, 28 Oct 2006, matt neuburg wrote: > > > Jason Merrill wrote: > > > > > And since Object is an ancestor of pretty much everything in ruby, > > > it's interesting to note that these methods are now defined for > > > practically everything in ruby: > > > > > > irb(main):001:0> def say_hello > > > irb(main):002:1> "Hello" > > > irb(main):003:1> end > > > => nil > > > irb(main):004:0> say_hello > > > => "Hello" > > > irb(main):005:0> [1,3,5].say_hello > > > => "Hello" > > > > But that's just a vagary of how irb works. You couldn't do that in a > > real script. m. > > Why not? say_hello is now a method of Object, an ancestor of [1,3,5]. > Challenge: show us what the error is when it fails. :-) matt-neuburgs-imac-g5:~ mattneub$ ruby def howdy puts "hi" end [1,2,3].howdy -:4: private method `howdy' called for [1, 2, 3]:Array (NoMethodError) m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Tiger - http://www.takecontrolbooks.com/tiger-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com