There are two kinds of programming languages that are unsurprising to the programmer. The first kind has users that say, "Everything about this language is unsurprising." The second has users that say, "Nothing about this language surprises me any more." --after a conversation with Pete Forde
You probably know that Ruby supports writing parameter-less blocks using begin
and end
:
fu = begin
a = 1
b = 2
c = 3
a + b + c
end
# => 6
You may also know that you can use parentheses with multiple lines:
fu = ( a = 1
b = 2
c = 3
a + b + c )
# => 6
I didn't know that! As usual, semi-colons work as separators:
fu = ( a = 1
b = 2; c = 3
a + b + c )
# => 6
The sharp-eyed amongst you may have noticed that some of these statements could be combined with Ruby's destructuring assignment:
fu = ( a, b, c = 1, 2, 3
a + b + c )
# => 6
But that's a different language feature. Okay, that's enough lingua obscura for today.
My recent work:
- JavaScript Allongé, CoffeeScript Ristretto, and my other books.
- allong.es, practical function combinators and decorators for JavaScript.
- Method Combinators, a CoffeeScript/JavaScript library for writing method decorators, simply and easily.
- jQuery Combinators, what else? A jQuery plugin for writing your own fluent, jQuery-like code.
(Spot a bug or a spelling mistake? This is a Github repo, fork it and send me a pull request!)