From: Eloy D. <elo...@gm...> - 2007-10-30 09:23:54
|
Hello list, I'm wondering how I should override #init from a module. If I use the following code, then it complains about super_init. I now have to use #initialize which works. But my code can't be used from the objc side of the bridge, so I'd rather use #init. Cheers, Eloy = = ======================================================================== require 'osx/cocoa' #$RUBYCOCOA_DEBUG = true module Foo def init puts 'INIT' self if super_init end def initialize puts 'INITIALIZE' end end class OSX::NSObject class << self alias_method :before_inherited, :inherited def inherited(subclass) before_inherited(subclass) subclass.class_eval do include Foo end end end end class Bar < OSX::NSObject end Bar.alloc.init # Produces: # # # INITIALIZE # INIT # # OSX::OCMessageSendException: Can't get Objective-C method signature for selector 'super:init' of receiver #<Bar:0x208370 class='Bar' id=0x5594e0> # # method ocm_send in oc_wrapper.rb at line 50 # method method_missing in oc_wrapper.rb at line 50 # method init in untitled document at line 8 # at top level in untitled document at line 30 |