On Wed, Aug 3, 2011 at 3:54 AM, luke gruber <luke.gru / gmail.com> wrote:
>>I would separate the leading from determining the set of instances to lead.

> I don't quite understand your example code.

There are two parts:

1. The method call propagation is done by instances of class Leader
which inherits BasicObject in order to have the minimum set of
predefined methods.  A Leader takes an Enumerable as source for
instances to delegate to, which means you can stuff in anything which
is Enumerable (e.g. Array, Set).

2. Then I created a class Source which is also Enumerable and happens
to look into ObjectSpace whenever someone wants to iterate via #each.
So, ObjectSpace would be only one way to look for instances.

>>class Module
>>   
>>   
>>
>>  
>>    >>   >
> ObjectSpace.each_object takes, as its first argument, a module.

... or a class.  Correct.

> I thought
> :cl was an instance variable of instances of the Source class. I don't
> know much about structs, so I'd love an explanation.

In the example "cl" is a member of the Struct which means there is a
pair of accessor methods, so "cl" really is a call to the getter.  And
the getter is set to "self" in Module#lemmings (which is an instance
method of all modules and classes).

Struct is really a handy way to quickly create a class with a few
properties which also gives you #hash and #eql?.  You can read more at
http://blog.rubybestpractices.com/posts/rklemme/017-Struct.html

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/