Differences between Keyword Arguments in Ruby 2.0 and Interleaved method signatures in Objective-C -
i've been playing macruby, , noticing how extends ruby able handle smalltalk-like method (or message) signatures of objective-c. @ first glance, thought looked lot new keyword arguments of ruby 2.0, further inspection shows work in fundamentally different way.
my first clue when reading macruby method spec on github.
it "can have multiple arguments same name" def @o.dosomething(x, withobject:y, withobject:z); x + y + z; end @o.should have_method(:'dosomething:withobject:withobject:') @o.should_not have_method(:'dosomething') end
as far know, behavior not allowed in ruby 2.0, because withobject:
part used sole identifier parameter, , therefore there not 2 same name.
is insurmountable problem? macruby forced remain ruby 1.9 because of this?
the key difference between keyword arguments , interleaved arguments you've guessed; keywords not part of method name (the selector in objective-c).
specifically, can't reorder or drop parts of objective-c method's selector because naming different method.
this why obj-c graybeards bristle whenever describes objective-c methods having keywords preceding each argument.
you might find question , answers on particular question relevant. brad cox -- 1 of inventors of objective-c -- answered.
Comments
Post a Comment