3 ms·
This is a little bit of an older article and Apple has since been working on MacRuby (http://www.macruby.org/trac/wiki/MacRuby http://www.macruby.org/trac/wiki/
by devrieda 18y ago
This is a little bit of an older article and Apple has since been working on MacRuby (http://www.macruby.org/trac/wiki/MacRuby http://www.macruby.org/trac/wiki/MacRuby) which is poised to replace RubyCocoa. MacRuby adds a special syntax to Ruby to better deal with the keyed arguments. From the docs:
Objective-C:
NSWindow *window = [[NSWindow alloc]
initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:false];
RubyCocoa:
window = NSWindow.alloc.initWithContentRect_styleMask_backing_defer(
frame,
NSBorderlessWindowMask,
NSBackingStoreBuffered,
false)
MacRuby:
window = NSWindow.alloc.initWithContentRect frame,
styleMask:NSBorderlessWindowMask,
backing:NSBackingStoreBuffered,
defer:false
- look_lookatme 18y agoThis is not a special syntax. It's just ruby 1.9 specific hash literal syntax.
- jimbokun 18y agoBut it looks like the important thing is that they have found a way to automatically map this syntax to Objective C method names. EDIT: Or, as the MacRuby docs put it: "MacRuby has a modified version of the parser which detects calls or method definitions using one regular argument, and other arguments using the key/value pair syntax. It will reconstruct the Objective-C full selector if needed. The method name that will be used in the Ruby VM is the same as the Objective-C selector." http://www.macruby.org/trac/wiki/HowDoesMacRubyWork http://www.macruby.org/trac/wiki/HowDoesMacRubyWork