From: LAMBEAU Bernard Date: 2009-01-10T00:22:48+09:00 Subject: Re: How Ruby Ruby allows you to install methods on objects (called singleton methods because installed on individual objects instead of being shared by all instances of a class): o = Object.new def o.sayhello puts "hello" end o.sayhello # prints hello to the console blambeau On Fri, Jan 9, 2009 at 3:25 PM, Stuart Ellis wrote: > > On 9 Jan 2009, at 13:30, David A. Black wrote: > >> Hi -- >> >> On Fri, 9 Jan 2009, Tom Cloyd wrote: >> >>> Thanks Mike. I appreciated your post. I'm an awful Ruby programmer, and >>> write tightly organized, well documented procedural Ruby. I'm only now, >>> after probably 1.5 years of on and off work in the language, getting around >>> to writing classes. I really couldn't see why I'd want to, until very >>> recently. Then, thanks to some folks on this list, I "got it". I can't wait >>> to dive in to using classes, now. >> >> Dave Thomas issued a challenge in a recent keynote address, where he >> suggested that when each of us writes our next Ruby program, we try to >> do it without writing any classes. It's an artificial exercise, of >> course, but it keeps the focus on the objects as opposed to the class >> hierarchy, which is all to the good in most cases. >> >> When I teach the Ruby language, I actually illustrate singleton >> methods before I talk about classes, because I consider the dynamism >> of objects (their independence from their classes) to be a more >> important foundational principle of Ruby than the fact that every >> object is an instance of a class. Mind you, like everyone else I write >> "class Thing" more often than "def thing.something" in my own code (I >> think :-) But it's still important, in my view, to get the hang of the >> fact that Ruby classes are not the center of gravity. >> >> So it sounds like you've done it in the right order :-) Keep modules >> in mind, too. They're very cool, especially when you #extend objects >> with them.... > > *Raises hand* > > At the risk of looking very silly, could I ask you to say a bit more about > this? As a newbie, I have automatically read "object" to mean "an instance > of a defined class", and assumed that object orientation in Ruby leads to > mostly thinking in terms of classes. > > Thank you, > > -- > Stuart Ellis > http://www.stuartellis.eu > > >