Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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

Foo.new.initWithThingOne "1", andThingTwo: "2"
=>
1
2
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top