On Feb 28, 2008, at 3:04 PM, Laurent S. wrote:
|> instance of C do with this?
duck.foo: 1, bar: 2
maybe? I am not sure if the parser allows this or not yet.
I thought about working up for Objective-C calling support via this
O[duck :foo => 1, :bar => 2]
At one point, I had a small parser change that allowed this to be
O[duck foo: 1, bar: 2]
The idea was that the rubinius compiler would detect this special form
and emit the ‘right thing’.
I think a bit part of this is whether you expect users (and other
code) to know they’re calling out to Objective-C, or if you want tight
integration. This is essential what matz says.
By making special Objective-C syntax, then you can’t pass in an
Objective-C object and expect it to be duck-typed like normal ruby
objects. But the trade off is that the syntax is less elegant. I think
it’s a trade off, and my 2 cents is you should opt for the more
elegant syntax. This is because there are only a few tiny edge cases
where the Objective-C selector matches the ruby selector, where you’d
want to allow the ObjC object to be duck typed as something else.
Thus, since the method names are so radically different, it’s better
that the user know “ok, I’m calling this other kind of method, so I
need to use this syntax.”
If they want to duck-type it, then let them write a wrapper for the
def call_objc(a, b)
O[duck foo: a, bar: b]
Something else that has not been brought up (that I saw) is whether
ruby methods are available as Objective-C methods. Can ruby methods be
called directly via the ObjC runtime?