Archive for September, 2007

Real Class

« 28 September 2007 | 8:23 | Smalltalk, JRuby, Ruby Internals, MRI | 5 Comments »

It interesting that Ruby, a language which allows you to so easily bypass encapsulation, encapsulates it’s own internals to the point of occasional prevarication. Heres an example…

pirate = Object.new
def pirate.speak
“Yarrrr”
end
pirate.class == Object.new.class
#=> true

In my last post I explained how the code above forces the interpreter to assign a newly created Singleton class to the […]



The Singleton Class

« 21 September 2007 | 9:47 | Ruby Internals, MRI | Comments Off »

There’s no shortage of literature on singleton classes, but it’s rare to see an explanation that covers implementation. This is unfortunate, as the implementation is not complex and familiarity with it leads to a more nuanced understanding.
A good way to look at singleton classes is to ask the question, “What is it that Ruby […]



Method Dispatch

« 14 September 2007 | 9:56 | Ruby Internals, MRI | Comments Off »

A good understanding of method dispatch can help in deciphering some of the odder corners of the Ruby object model. Luckily, method dispatch is not only straight forward, but entirely consistent for “normal” methods, singleton methods, and module methods.
In Matz’s Ruby Interpreter (MRI), method bodies are stored in a struct devoted to representing […]