From: "David A. Black" Date: 2009-07-15T05:35:41+09:00 Subject: Re: Twelve rules of Ruby Hi -- On Wed, 15 Jul 2009, Ryan Davis wrote: > > On Jul 14, 2009, at 06:16 , David A. Black wrote: > >> Not sure why they wrapped weirdly (at least on my screen), but here's >> a correctly-wrapped version, I hope. > > Rick did a very good job with some of the philosophical wanking but I thought > I'd expand a bit on David's list... I have to be a pedant now and then :) > > (please note, I'm still pre-caffeine... I'm sure I missed something in the > editing phase) > >> 1. Classes are objects. > > I prefer to tell my students: EVERYTHING is an object, even classes. > > I think it conveys the ontology a bit better. Well -- either one is shorthand, in the sense that when actually teaching the stuff, much more than one sentence is required :-) >> 2. Objects don't "have" methods; they have the intelligence to resolve >> messages by looking for methods along their class/module lookup >> path. > > See #1. Classes, modules, and their anonymous kin _have_ methods. Of course. Otherwise there wouldn't be much point looking for a method along a lookup path of them :-) That's really the point of the "has" thing: objects don't define or own the methods to which they have access. At the very least, ownership is class-mediated, including as between a class object and its own singleton class. (I know the whole singleton class thing is an implementation decision, but, at least for now, it's a decision, rather than an incidental detail.) >> 3. Every instance variable you ever see in any Ruby program belongs to >> whatever object "self" is at that moment, without exception. (Which >> is one reason that understanding how "self" gets assigned is >> absolutely vital.) >> 4. A code block is a syntactic construct, not an object. > > See #1. EVERYTHING is an object, even blocks. I don't consider blocks or argument lists to be objects. >> 5. Class variables are not class variables, in the sense of belonging >> to a particular class. They are class hierarchy variables. > > I know what you're getting at, but it might be worth having the contrast of > class instance variables in there so others understand too. Do cut me some slack :-) I really wasn't trying to write a tutorial -- just a list of very succinct, suggestive, almost epigrammatic points. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN)