もしもし RSS

Archive

Aug
16th
Sat
permalink

Simple Ruby

Let’s take a look at this trivial Ruby example:

[1, 2, 3, 4].each { |i| puts i }

The first thing we notice is that the commas shouldn’t be necessary:

[1 2 3 4].each { |i| puts i }

We can also go Smalltalk style and remove the dot. Many languages do that, including the minimalist Io, so here we go:

[1 2 3 4] each { |i| puts i }

It’s shorter already, but now let’s switch to Groovy style, with the implicit ‘it’ object:

[1 2 3 4] each { puts it }

Can it be even shorter? Let’s try this:

[1 2 3 4] each puts

That’s better, now the ‘it’ becomes implicit too. Even if we removed some formatting, I think anyone with a programming background can understand what’s happening here and what the output will be.

For those of you interested in this syntax: the last version is valid Raven code.