3

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 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
end

2 Answers 2

9

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.

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

Comments

5

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.

Comments

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.