Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby for in loop error with { } block delimiter

Tags:

In the language Ruby the following works in irb

for fruit in ['apple', 'banana', 'cherry', 'date'] do
    puts fruit 
end

but this one does not

# error
for fruit in ['apple', 'banana', 'cherry', 'date'] { puts fruit } 

please note for reference the following block delimiters do not error

5.times do |i|
    puts "hello "+i.to_s
end

5.times { |i| puts "hello "+i.to_s }

Edit: I guess what I'm observing is an inconsistency with the way do end is substituted for { } can someone explain why or please point out my mistake?