Melanie Shebel Melanie Shebel -4 years ago 193
Ruby Question

Syntax Error: unexpected keyword_do_block

I got this new Ruby book and I'm trying out some of the sample problems in the book and I'm getting a syntax error: unexpected keyword_do_block.

I have written similar 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

Answer Source

Replace to:

temp.each do |e|
  # ...

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download