5/8 Syntax explained


I just want to understand proper ruby with this question.

I have submitted the 2 following lines of code on this particular challenge and both have given me a clear. Can someone explain why this is?

words.each { |word| frequencies[word] += 1 }

words.each do |word| frequencies[word] += 1

Notice one of these has curly braces while the other includes the keywords do and end, but no braces. Why is this possible? Just trying to wrap my head around the small things to help me understand this language more.



Ruby was created to be read and typed to understand easily. For programmers who are more accustomed to using Curly brackets that's an option, while other who want to read things easier can use the "do / end" Do and End are like { and } to ruby.

The same way that you can say "13.times do /*code*/ end" It's really easy to read from left to right and would work the same way if you used the curly brackets.


I just saw a different example of this and I totally get it!

Appreciate your response though!


Great question! And a great answer! :slight_smile: