I’m trying to learn the ruby way of doing things, and ran across some
code that I’m finding hard to understand. It seems to be sending
extend and include messages of inner modules to the class def itself.
I’ve boiled the sample down to something like this.
‘Class method c1’
def c2 'Class method c2' end
send :extend, ClassMethods
‘Instance method i1’
def i2 'Instance method i2' end
send :include, InstanceMethods
I think I must be missing something.
Isn’t the receiver of the send message the Class itself? If not, who
is the receiver?
If it is, what does this technique offer compared to just declaring
the class and instance methods in the first place?
I’d really appreciate some clarification about this style.