[Rubycocoa-devel 949] Re: Dynamically define a class

Zurück zum Archiv-Index

kimura wataru kimur****@i*****
Tue Jun 5 22:49:52 JST 2007


Hi,

RubyCocoa add an ObjC class fro by its name
at NSBehaviorAttachment#ns_inherited (in oc_import.rb)
Ruby generate a unnamed class 

On Tue, 5 Jun 2007 11:17:02 +0200, Eloy Duran wrote:
> Hello guys,
> 
> In revision 1816 I added the code to dynamically define a class when a
> ActiveRecord::Base subclass is defined.
> However at the moment the only way I could get this to work is by
> using old evil eval, but I would rather define it with
> Object.const_set().
> If I use Object.const_set() I get the following error:
> 
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/oc_import.rb:323:in
> `objc_instance_method_type': no implicit conversion from nil to
> integer (TypeError)
>         from 
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/oc_import.rb:323:in
> `_ns_enable_override?'
>         from 
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/oc_import.rb:313:in
> `_ns_behavior_method_added'
>         from 
> /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/objc/oc_import.rb:618:in
> `method_added'
>         from tc_active_record.rb:39
> 
> The code:
> class ActiveRecord::Base
>   class << self
>     alias_method :__inherited_before_proxy__, :inherited
>     def inherited(klass)
>       proxy_klass = "#{klass.to_s}Proxy"
>       unless Object.const_defined?(proxy_klass)
>         # eval "class ::#{proxy_klass} < OSX::ActiveRecordProxy; end;"
>         # FIXME: This leads to a TypeError originating from:
> oc_import.rb:618:in `method_added'
>         Object.const_set(proxy_klass, Class.new(OSX::ActiveRecordProxy))
>       end
>       self.__inherited_before_proxy__(klass)
>     end
>   end
> end
> 
> Could somebody explain to me why this error occurs?
> 
> Cheers,
> Eloy
> 
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Zurück zum Archiv-Index