开发者

Syntax Error: unexpected keyword_do_block

开发者 https://www.devze.com 2023-03-22 23:50 出处:网络
I\'m trying out some sample problems from a learn Ruby book and I\'m getting a syntax error: unexpected keyword_do_block.

I'm trying out some sample problems from a learn Ruby book and I'm getting a syntax error: unexpected keyword_do_block.

I have written si开发者_如何转开发milar code a billion times before and see nothing wrong (maybe I'm just daft tonight.) Can anyone see what I'm doing wrong?

The code:

temp = ["34","35","36","45","534","86","443","54","23","54","75","54","73"]

temp.each |e| do
  fahrenheit = (e * 9 / 5) + 32
  puts fahrenheit
end


Replace to:

temp.each do |e|
  # ...
end

Also, you can't do math operations with String, remove all quotes from the array or use e.to_i within the block.


The problem is in your each block definition:

temp.each |e| do

should be:

temp.each do |e|

And, don't feel that you are daft. We ALL have times staring at code, when we can not see what is wrong. Having extra sets of eyes to find the problem is what pair-programming is all about.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号