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

StackOverflow https://stackoverflow.com/questions/10463906

  •  06-06-2021
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

class Foo
  def initWithThingOne(one, andThingTwo: two)
    puts one
    puts two
  end
end

Foo.new.initWithThingOne "1", andThingTwo: "2"
=>
1
2
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top