rubycalabash-ios

Ruby - syntax error, unexpected tLABEL


I am getting syntax error, unexpected tLABEL in below Ruby code. The error description is pointing to ':' after 'timeout'.

def self.run(*args, timeout: nil, environment: {})
  # ...
end

I have no knowledge of Ruby. I have tried few things like replacing ':' with '=' or putting nil in {} but nothing seems to work.

My ruby version is 2.1.5.

IUQ-mini:~ IUQ$ rbenv versions
system
* 2.1.5 (set by /Users/IUQ/.ruby-version)
2.1.7
2.2.3

The particular code can be found here at line #38.

Few questions over SO points that this could happen due to misplaced braces but I did not see error - again my lack of Ruby knowledge!

Please help me to understand cause of this error and How can I resolve this?

Thanks


Solution

  • That won't work in ruby 1.9 (if in fact JRuby is limiting you to 1.9) as-is since the splat is expected to have a hash immediately following it if it's the first argument.

    You can do something like this:

    def self.run (environment = {}, timeout = nil, *args)
    end
    

    The only rub is you'll have to explicitly pass something (even nil) for timeout if you want to pass stuff in to be args[].