Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Motion Manually Create syntactically similar Objective-C-like functions in Ruby

Ruby Motion comes with a lot of pre-built functions that are formatted like this:

def tableView(tv, numberOfRowsInSection:section)
  # blah
end

I want to delcare my own functions like this; contrived example:

class Timeser
  def multiplyNumber(one byNumber:two)
    one*two
  end
end

This code will not compile under ruby motion 1.0... Is there a way to do this? If so, how?

like image 266
pachun Avatar asked Aug 17 '26 05:08

pachun


1 Answers

You're missing a comma:

class Timeser
  def multiplyNumber(one, byNumber:two)
    one*two
  end
end

Result:

(main)>> Timeser.new.multiplyNumber(2, byNumber: 3)
=> 6
like image 187
pschwamb Avatar answered Aug 19 '26 08:08

pschwamb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!