What Is Ruby?
Ruby is a general-purpose programming language known for readable, expressive code. It was created by Yukihiro "Matz" Matsumoto in Japan and first released in 1995. Matz's stated goal was a language that makes programmers happy — code that reads close to plain English.
3.times { puts "Hello, Ruby!" }
Hello, Ruby!
Hello, Ruby!
Hello, Ruby!
Even without knowing Ruby, you can probably guess what that line does. Its defining traits:
- Interpreted — you run a
.rbfile directly with therubycommand; there is no separate compile step to manage. - Dynamically typed — you don't declare a variable's type. A variable can hold a number now and text later.
- Everything is an object — even numbers and
nilhave methods you can call, such as3.timesabove or-5.abs. - Blocks — the
{ ... }chunk above is a block: a piece of code you hand to a method. Blocks are everywhere in Ruby and are covered in their own lesson. - Garbage collected — Ruby frees memory automatically, so you never manage memory by hand.
Ruby is also a scripting language: the same language you use for a large web application works just as well for a ten-line script that renames files on your computer.