Ruby
Created by Yukihiro "Matz" Matsumoto in 1995, Ruby is a dynamical object-oriented programming language. It's built/inspired by Perl, Smalltalk, Eiffel, Ada, and Lisp.
Matz, speaking on the Ruby-Talk mailing list, May 12th, 2000.
Ruby is simple in appearance, but is very complex inside, just like our human body
Factoid
In Ruby everything is objects, so no primitives. Parentheses are also optional. Opening up for some interesting coding, but that doesn't mean that you have to avoid them.
Is this really that readable?
puts array.delete hash.fetch :foo
Snippet 1
Use the $
to create global variables, but don't clutter the namespace please.
Snippet 2
To create a new hash, all you need to type is {}
.
Snippet 3
Ruby uses nil
as a false value. So no need to do var.nil?
everywhere.
Snippet 4
puts
is used to print a string version of an object with a new line at the end. Short for "put string".
Snippet 5
To make Ruby even more powerful it handles closures. And with the use of f.call
you can call/invoke a block or function. Pretty sweet. For those unfamiliar with closures. A closure can pass it around like an object (to be called later). It also remembers the values of all the variables that were in scope when the function was created. It can access those variables when it is called even though they may no longer be in scope.
Snippet 6
The snippet class C
returns nil, and that is because everything in Ruby has a return value. You can even return multiple values.
Snippet 7
With the use of include
Ruby support single inheritance. Making it easy to mixin modules.