Ruby Motion附带了许多预先构建的函数,其格式如下:
def tableView(tv, numberOfRowsInSection:section)
# blah
end
我想像我这样去看看自己的功能;人为的例子:
class Timeser
def multiplyNumber(one byNumber:two)
one*two
end
end
此代码不会在ruby motion 1.0下编译...有没有办法做到这一点?如果是这样,怎么样?
答案 0 :(得分:7)
你错过了一个逗号:
class Timeser
def multiplyNumber(one, byNumber:two)
one*two
end
end
结果:
(main)>> Timeser.new.multiplyNumber(2, byNumber: 3)
=> 6
答案 1 :(得分:0)
class Foo
def initWithThingOne(one, andThingTwo: two)
puts one
puts two
end
end
Foo.new.initWithThingOne "1", andThingTwo: "2"
=>
1
2