[MacRuby-devel] #init, or #initialize

Eloy Durán eloy.de.enige at gmail.com
Thu Feb 24 05:26:31 PST 2011


I use #init whenever I’m dealing with Cocoa(-like) classes and #initialize when it's pure Ruby. I do the same with regards to camel and snake casing. Also note that #init is not supposed to take arguments, whereas #initialize may definitely do so.

Any classes that inherit from NSObject directly will have #initialize called if #init is called on them:

% cat t.rb
class PureRubyClass
  def initialize
    puts "here!"
  end
end

PureRubyClass.alloc.init

% macruby t.rb
here!

On Feb 24, 2011, at 1:46 PM, Rob Gleeson wrote:

> Hi
> 
> It seems on MacRuby 0.8 that a subclass of NSWindowController has #init called, but #initialize is not called.
> It seems really odd to have two different initialize methods, and particularly when one of them breaks away from 
> what is convention in Ruby. Is this intended? 
> 
> 
> Thanks
> Rob
> 
> 
> 
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list