Manual ruby ​​engine Create syntactically similar Objective-C-like functions in Ruby

Ruby Motion comes with many built-in functions that are formatted as follows:

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

I want to do my own functions; far-fetched example:

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

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

+3
source share
2 answers

You are missing a comma:

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

Result:

(main)>> Timeser.new.multiplyNumber(2, byNumber: 3)
=> 6
+7
source
class Foo
  def initWithThingOne(one, andThingTwo: two)
    puts one
    puts two
  end
end

Foo.new.initWithThingOne "1", andThingTwo: "2"
=>
1
2
0
source

All Articles