#init, or #initialize
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
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@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 24 Feb 2011, at 13:26, Eloy Durán wrote:
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!
Alright, thanks for clarifying. The camelCase and snake_case difference is something I've been trying to get use to as well. I think I'll adopt your style :) -- Rob
participants (2)
-
Eloy Durán
-
Rob Gleeson