Laurent Sansonetti
lsans****@apple*****
Wed Jun 7 23:36:02 JST 2006
Hi all, Someone here talked me about that calling convention that Rails is using: obj.foo(:key => val, :key2 => val2, ...) and suggested that RubyCocoa uses it. I believe that this convention is prettier than the current symbol- value-symbol-value..., and sounds more like Objective-C. I patched the unstable branch to support it (and added a test-case), you can now do this: url1 = NSURL.alloc.initWithScheme_host_path('http', 'localhost', '/foo') url2 = NSURL.alloc.initWithScheme('http', :host, 'localhost', :path, '/foo') url3 = NSURL.alloc.initWithScheme('http', :host => 'localhost', :path => '/foo') On the implementation side, the change was very trivial. But there is this common problems with Hash tables where the keys ordering is undefined, so when you pass :host before :path we may receive it in a different order when parsing the Hash. That's why for Hash of size > 1 it is necessary to do some introspection in order to build the correct ObjC selector with the right arguments order. Right now introspection is done each time, doing some caching there should improve the performances. And of course it comes problematic if in Objective-C you have - (void)doSomethingWith:(id)object name:(id)name value:(id)value; - (void) doSomethingWith:(id)object value:(id)value name:(id)name; as we could call the wrong method. But this is very rare :-) Tell me what you think, Laurent