0

I am using ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux] where I am trying to test a script. The following does not work as expected

CSV.foreach(tscm_hosts_file, headers: tscm_hosts_file_col_headers) do |row|
  catch :bad_data do
    tscm_hosts_file_col_headers.each do |header|
      throw :bad_data if row[header].nil?
    end
.
.....

And error received is

[root@fmsprdchef001 ~]# ./generate_autoreg_output.rb
./generate_autoreg_output.rb:75: syntax error, unexpected ':', expecting ')'
...each(tscm_hosts_file, headers: tscm_hosts_file_col_headers) ...

I think this is the because of the ruby version I am using. Can someone tell which RUby version supports this syntax?

1 Answer 1

2

Move from

CSV.foreach(tscm_hosts_file, headers: tscm_hosts_file_col_headers)

to

CSV.foreach(tscm_hosts_file, :headers => tscm_hosts_file_col_headers)

The new hash syntax for symbols has been introduced in Ruby 1.9

Sign up to request clarification or add additional context in comments.

5 Comments

so to use the existing script I should move to 1.9 ?
Yes, for that syntax you need at least ruby 1.9. Is that script a gem, just a file you have or what?
Its just a .rb file
You can either use ruby 1.9 or fix that file to the old syntax. But other changes could be needed.
@aaj if changing ruby versions is an option you should do it even 1.9 has been out of support for quite some time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.