Ruby can use braces instead of end, both are valid.
Re:A taste of Rust
by lobster_johnson on Friday April 26, 2013 @01:27AM
(#5611632)
Hm? Only for blocks. Not classes, methods, if/unless, while or begin/rescue.
The general rule is, as with Python and Go, that open braces, brackets, parens or quotes have precedence; and operators or punctuation at the end of a line will continue to the next line.
In addition, there are some complicated parsing internals -- not just for expression-ending sensing, but also for supporting parens-less method calls -- that endow the parser with some compiler knowledge about what tokens are variables and what tokens are methods. In other words, the parser has information that violates the parser/compiler separation of concerns, but it works really well in practice.
The only time I ever use \ in Ruby is for string literals that need to be broken up for readability:
You can use + or <<, but this will be evaluated at runtime, whereas \ results in a single string allocation.Of course, Ruby requires "end" for a lot of constructs, but it could have just as well have used braces.