Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting syntax error, unexpected ':', expecting '=' in Ruby

I am very new to Ruby and trying to run a script ,When I am trying to run a Ruby script like below, I am getting

> ruby test.rb 
test.rb:53: syntax error, unexpected ':', expecting ')'
  All::Config.new_global_config(domain: domain, realm: realm)
                                          ^
test.rb:53: syntax error, unexpected ':', expecting '='
  All::Config.new_global_config(domain: domain, realm: realm)

When I see ruby version, it says:

> ruby -version
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
-e:1: undefined local variable or method `rsion' for main:Object (NameError)

Any pointers? Is it because of the version? 1.8.x instead of 1.9 or more?

like image 669
Mayank Mukherjee Avatar asked Jan 29 '23 19:01

Mayank Mukherjee


1 Answers

The {key: 'value'} syntax was added in ruby v1.9. To do this in v1.8, you need to use the {:key => 'value'} syntax (which is still valid in modern ruby, too).

1.8 and 1.9 are both very old versions!!! Neither has been supported for a long time. (1.8 was retired in 2013; 1.9 in 2015.)

The latest version, at the time of writing this, is 2.4.1. Use this if possible.

The oldest supported version of ruby is 2.2.7.

like image 192
Tom Lord Avatar answered Feb 11 '23 16:02

Tom Lord