[MacRuby-devel] Objective-C class +initialize in MacRuby
Matt Aimonetti
mattaimonetti at gmail.com
Sun Oct 10 11:15:39 PDT 2010
$ macruby -e "class Foo; def initialize; puts '10/10/10'; end; end;
Foo.new"
10/10/10
The problem in your example is that in Ruby, the constructor is an instance
method, not a class method.
So your mistake was to define self.initialize instead of just initialize.
class Foo
def initialize
puts "initialize is a haaaapy panda"
end
end
Foo.new
- Matt
On Sun, Oct 10, 2010 at 11:35 AM, Caio Chassot <lists at caiochassot.com>wrote:
> Hi,
>
> It looks like self.initialize is a no-go:
>
> class Foo
> def self.initialize
> NSLog("self.initialize is a saaaad panda") # <- never runs
> end
> end
>
>
> The ruby idiom for that would be just:
>
> class Foo
> NSLog("IM IN UR CLASS INITIALIZEEN FROM RUBY")
> end
>
> is that ok in the context of Cocoa applications? Is there a better way?
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101010/64ceacab/attachment.html>
More information about the MacRuby-devel
mailing list