On 2010-10-10, at 17:24 , Laurent Sansonetti wrote:
> 
> Indeed, +initialize won't be called for pure-Ruby classes. I recommend to use 
> the Ruby idiom here, it's simpler :)

So, the problem I'm seeing is what I alluded to earlier: writing stuff in the 
class body is more like +load than +initialize. Especially, not all classes may 
be loaded at that point.

So I came up with this: http://gist.github.com/619585

Would it make sense to try to have something official for this functionality?


In the process I noticed a few things:

1. You may see I opted for using _initialize instead of initialize for the 
method name. It turns out every ruby class in MacRuby already 
respond_to?(:initialize). That's not true in MRI. Is this a necessity of the 
Objective-C implementation?

2. It appears that the #singleton_class method does not exist in MacRuby. 
Oversight? File a ticket?

3. I initially tried implementing Object.inherited as:

    class Object
      @inherited = []
      def self.inherited(m)
        @inherited << m
      end
    end

This works in a standalone MacRuby file. In the context of an application, 
@inherited seems to be lost, and I get an error trying to call << on nil. 
What's going on here?

_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to