Re: [MacRuby-devel] super_foo style RubyCocoa messages.
I've started work on a RubyCocoa layer for MacRuby (still very naive).
Like already discussed with Laurent, an API to be able to call the superclass implementation of a method will be necessary for super_foo style methods to work. Imagine this code:
class Foo < OSX::NSObject def init self if super_init end end
Something like this will be needed:
class OSX::NSObject def method_missing(mname, *args, &block) if superclass_method?(mname) # convert mname to selector super_send(selector, *args) # <- #super_send (or something like it) should be able to send a message to the superclasses implementation. else original_method_missing(mname, *args, &block) end end end
I hope this is clear enough?
It is, but I have to say that I always found the super_foo syntax confusing in RubyCocoa. That's probably because I came to Ruby from ObjC, not ObjC from Ruby... I kept wishing that:
super.foo() would work. Is that possible?
Hi Pierce, That syntax wouldn't work because calling "super" will call the method you're in from the superclass. AND it may/will return an object. In your example you are calling #foo on the result object of the super call. But that would be the functionality I suggest yes. About the weird syntax in RubyCocoa, I agree. But this wouldn't be a compatibility layer without supporting it's intricacies now would it :) Eloy PS: Is it me or is the return-path for the emails coming from the ML incorrect? I guess it should point to macruby- devel@lists.macosforge.org instead of Pierce...
It is, but I have to say that I always found the super_foo syntax confusing in RubyCocoa. That's probably because I came to Ruby from ObjC, not ObjC from Ruby... I kept wishing that:
super.foo() would work. Is that possible?
Hi Pierce,
That syntax wouldn't work because calling "super" will call the method you're in from the superclass. AND it may/will return an object. In your example you are calling #foo on the result object of the super call.
But that would be the functionality I suggest yes.
About the weird syntax in RubyCocoa, I agree. But this wouldn't be a compatibility layer without supporting it's intricacies now would it :)
Hmmm... Given that this is something where Ruby/ObjC (or for that matter Java) butt heads, I wonder if there should be a better syntax? Like: def bar() superclass.foo() # call the superclasses implementation of foo() end I could probably learn to remember to type superclass instead of super. Pierce
Eloy
PS: Is it me or is the return-path for the emails coming from the ML incorrect? I guess it should point to macruby-devel@lists.macosforge.org instead of Pierce...
That happens to me as well.
On May 6, 2008, at 10:10 AM, Pierce T. Wetter III wrote:
It is, but I have to say that I always found the super_foo syntax confusing in RubyCocoa. That's probably because I came to Ruby from ObjC, not ObjC from Ruby... I kept wishing that:
super.foo() would work. Is that possible?
Hi Pierce,
That syntax wouldn't work because calling "super" will call the method you're in from the superclass. AND it may/will return an object. In your example you are calling #foo on the result object of the super call.
But that would be the functionality I suggest yes.
About the weird syntax in RubyCocoa, I agree. But this wouldn't be a compatibility layer without supporting it's intricacies now would it :)
Hmmm... Given that this is something where Ruby/ObjC (or for that matter Java) butt heads, I wonder if there should be a better syntax? Like:
To clarify, we are not talking about introducing any new syntax or "public" API in Ruby, but to introduce a way that the RubyCocoa compatible layer can use to translate "super_foo" messages as a "super" call. The way would most probably be private (__send_super__ ?) and could be implemented as a C extension. Before (RC): def initWithName(name) super_initWithName(name) end Now (MR): def initWithName(name) super # just works end Laurent
Hmmm... Given that this is something where Ruby/ObjC (or for that matter Java) butt heads, I wonder if there should be a better syntax? Like:
To clarify, we are not talking about introducing any new syntax or "public" API in Ruby, but to introduce a way that the RubyCocoa compatible layer can use to translate "super_foo" messages as a "super" call. The way would most probably be private (__send_super__ ?) and could be implemented as a C extension.
Before (RC):
def initWithName(name) super_initWithName(name) end
Now (MR):
def initWithName(name) super # just works end
Yeah, I get that but what if you want the common ObjC idiom where you add a new initializer and then call the super classes implementation of the old one? def initWithName(name) - initWithName: (NSString *) inName { self=super_init() id self = [super init]; @name=name name= inName; return self return self; end } super() isn't appropriate in this case. I don't like super_init() there. I think its ugly syntax, and its less clear then: super.init() would be, or even: superclass.init(). or _super.init() Pierce
participants (3)
-
Eloy Duran
-
Laurent Sansonetti
-
Pierce T. Wetter III