Search code examples
objective-cmethodsrubymotion

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?


Solution

  • 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