On 10/23/07, Thufir [email protected] wrote:
“One secret about kernel methods like print: they are
actually class methods,” according to why’s poignant guide to ruby.
This is frustrating for me, because I first thought “oh, that’s like a
static class method, a la Math.whatever(),” and then accepted the
Kernel means class methods?
No, and I don’t understand what why means.
print is an instance method of the Kernel module.
The Object class includes Kernel, so the instance methods of Kernel
are effectively instance methods of every object, at least in Ruby
I think the only sense that print is a class method is that Module,
and therefore Class inherits it from Object which gets it from
including Kernel. In the same sense then ==, object_id, … are class
methods. In other words classes are objects.
Ruby 1.9 introduces a BasicObject which doesn’t include kernel and can
be used for advanced use cases such as proxies which need to minimize
the number of methods they implement.
My blog on Ruby