Mixing in kernel
Yesterday I posted on my desire to port over attr_accessor, which I’m realizing is a lofty goal for myself, but we’ll see where it brings me. The IronRuby team has already done some of the legwork, though. If you search the source for attr_accessor you find a comment about it in Ruby\BuiltIns\ModuleOps. So if I’m following correctly, a module, much like in MRI, is a set of code that can be thrown around, and usually used as a mixin to another class. For those unaware of a mixin, think of it simply as arbitrary code you can add to classes, very much like extension methods for those of us .net geeks.
As I often do, I got sidetracked here, and jumped over to Kernel.cs. Just yesterday I was having a conversation with Jason, the other guy that has posted here so far. He’s been diving into the Ruby source more then myself, and was explaining how Kernel includes many of the common methods, and just simply gets mixed into object. He then started down how it gets into irb, but I think I spaced out at that point.
As I’m looking at kernel, I find the code below :
-
-
[RubyExtensionClass("Object", typeof(object)), Includes(typeof(Kernel))]
-
public static class ObjectOps {
-
So from what I can tell, IronRuby is doing the same thing under the covers. That shouldn’t really surprise me, but I was really impressed with how classes seem to be getting mixed in on the managed side, the attribute above is very clear and clean, and stays very close to “the Ruby way”.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply