Ruby takes a lot of inspiration from Smalltalk. Some of the similarity is odd, though.
In Smalltalk, symbols use the
# sigil (e.g.
#foo). In Ruby, symbols use the
: sigil (e.g.
In Smalltalk, you can get a method for a given name (selector) using
someArray lookupSelector: #sort. The name (or selector) of the method is a symbol. Ruby refers to methods using that same syntax as well, e.g.
#first — at least in documentation, because
# is used for comments in Ruby, not symbols.
The syntax for symbols using the
: sigil comes from Lisp.
In Ruby, you use
#each to iterate over a collection. A block is created using
things.each do |thing| … end
In Smalltalk, you use
do: to iterate over a collection. A block is created with
], and the conventional name for the argument is
things do: [:each | …]
Block argument variables start with
:, which resemble Ruby’s symbols.
When local variables are needed, they can be added using double pipes, e.g.
things do: [:each | |myLocal| …]
The double pipe syntax resembles Ruby’s syntax for block parameters.