Hi –
On Wed, 15 Jul 2009, Ryan D. wrote:
editing phase)
- 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
- 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.)
- 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.)- 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.
- 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