Rick
Rick

Reputation: 13

sublime text 2 ruby blocks with semicolons error

I'm trying out a simple Ruby program to learn about blocks and keep running into a build error when I try use semicolons inside the pipe characters.

If I run the file in Terminal using ruby name_of_program.rb, then everything runs fine. It is only when I try to build in Sublime Text that I get the error.

This is the program that errors out in Sublime Text 2 but runs fine outside of it:

x = 10

5.times do |x|
  puts "x inside the block: #{x}"
end

puts "x outside the block: #{x}"

x = 10
5.times do |y|
  x = y
  puts "x inside the block: #{x}"
end
puts "x outside the block: #{x}"

x = 10
5.times do |y; x|
  x = y
  puts "x inside the block #{x}"
end
puts "x outside the block #{x}"

And the error:

block_variables_ex.rb:21: syntax error, unexpected ';', expecting '|'
5.times do |y; x|

Any idea as to what I may be doing wrong?

Upvotes: 1

Views: 297

Answers (1)

snowe
snowe

Reputation: 1375

This has been answered in "Ruby: unexpected semicolon in block parameters" in regards to the exact error you are getting. It sounds like Sublime is maybe accessing an older version of Ruby.

Check your path to see if there are two versions of Ruby there and remove all references to Ruby 1.8.

Upvotes: 1

Related Questions