3 ms·
Ruby and JavaScript are a bit different. In Ruby, once you reach the end of a line, it is unambiguous whether the line is complete. You don't need to scan the
by wycats 14y ago
Ruby and JavaScript are a bit different.
In Ruby, once you reach the end of a line, it is unambiguous whether the line is complete. You don't need to scan the next line to figure it out.
Ruby does support a line continuation character if the line is complete, but you want to continue it anyway.
foo = Struct.new(:bar).new("HI")
puts foo \
.bar
So in Ruby, the rule is: if you get to the end of a line and the expression is complete, the expression is finished. Otherwise, continue on the next line.
This is really nice for human-readability (and as a side effect, pasting code into IRB).