From: sergio <sde...@gm...> - 2007-08-28 20:16:46
|
Hi all, this is my first post to this list. I have been recently playing with metaprogramming a RubyCocoa app using Core Data, and I got into a behaviour I don't fully understand when programmatically overriding an NSManagedObject method that takes no parameters, as didSave or awakeFromInsert. Say I have the following bit of code : class RCEntity < OSX::NSManagedObject .... def self.makeEntity(...) define_method(:awakeFromInsert) do super_awakeFromInsert # more stuff here end end end class TestEntity < RCEntity makeEntity(...) end (this code is not meant to be run) What I expect is that, due to the call to makeEntity, awakeFromInsert is overriden by TestEntity. What I get is the following error message: /Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/ objc/oc_import.rb:318:in `_ns_behavior_method_added': Cannot override Objective-C method 'awakeFromInsert' with Ruby method #awakeFromInsert, they should both have the same number of arguments. (expected arity 0, got -1) (RuntimeError) I am getting this behaviour in RubyCocoa 0.12.0 and 0.11.1. The same code works under RubyCocoa 0.10.1 (and previous versions that used the ns_override directive). Furthermore, this behaviour only is shown when overriding methods that take no parameters; everything works fine when overriding, say, willChangeValueForKey, which takes one parameter. I tried to override the didSave method as well (no parameters), and it also failed, so it seems to be related to the number of parameters. Of course, overriding always works when I am not doing it via define_method but plainly in the class definition. Any clues anyone? I am willing to explore further this issue on my own, provided there is no easy explanation, if someone is so kind to point me in the right direction.... Thanks in advance and best sergio |