RubyMotion comes with some syntax idioms that are not strictly idiomatic Ruby.
For example, in an iOS app we'd often see these two methods defined in a subclass of UITableViewController
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// callback code for selecting table rows goes here...
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// define the cell that should be returned at this IndexPath
}
Strictly speaking, these method names are tableView:didSelectRowAtIndexPath and tableView:cellForRowAtIndexPath - this comes from Objective-C's awkward syntax of defining parameters within method names.
To try and replicate this in Ruby, Ruby Motion uses a syntax that looks similar although semantically would carry a different meaning in idiomatic Ruby.
def tableView(tableView, didSelectRowAtIndexPath: indexPath)
# callback code for selecting table rows goes here...
end
def tableView(tableView, cellForRowAtIndexPath: indexPath)
# define the cell that should be returned at this IndexPath
end
Note that in Ruby, this would typically mean that a method named tableView had been defined, with the first parameter being named tableView and the second parameter being passed as a hash of options*. Also note that both of the methods defined here have the same name which, in a standard Ruby compiler, would result in the first method being overwritten by the second.
In RubyMotion, both methods are defined and compiled to their equivalent Objective-C methods in the iOS SDK.
*This is a syntax added to RubyMotion and would raise a syntax error in a normal Ruby interpreter. This was added to conform to the way Objective-C methods are called, Objective C methods have named parameters.