Ruby (programming language)

From Canonica AI

Overview

Ruby is a high-level, interpreted, general-purpose programming language that was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. Ruby is dynamically typed and uses garbage collection, and supports multiple programming paradigms, including procedural, object-oriented, and functional programming.

A screenshot of a Ruby code snippet in a text editor
A screenshot of a Ruby code snippet in a text editor

History

Ruby was conceived on February 24, 1993. In a 1999 post to the ruby-talk mailing list, Yukihiro Matsumoto describes some of his early ideas about the language: "I was talking with my colleague about the possibility of an object-oriented scripting language. I knew Perl (Perl4, not Perl5), but I didn't like it really, because it had the smell of a toy language (it still has). The object-oriented language seemed very promising. I knew Python then. But I didn't like it, because I didn't think it was a true object-oriented language — OO features appeared to be add-on to the language. As a language maniac and OO fan for 15 years, I really wanted a genuine object-oriented, easy-to-use scripting language. I looked for but couldn't find one. So I decided to make it."

Design philosophy

Ruby follows the principle of least astonishment (POLA), which means that the language behaves in such a way as to minimize confusion for experienced users. Matsumoto has said that he designed Ruby to be simple at its core, with an easily extendable system. He believes that systems designed in this way are easier to use and are more easily adaptable to changing needs.

Syntax

Ruby's syntax is broadly similar to that of Perl and Python. Class and method definitions are signaled by keywords, whereas code blocks can be defined by either keywords or braces. In contrast to Perl, variables are not obligatorily prefixed with a sigil. When used, the sigil changes the semantics of scope of the variable. Ruby has a variety of built-in operators, including arithmetic, comparison, assignment, and logical operators.

Semantics

Ruby is a single-pass interpreted language. Its semantics are very straightforward for a dynamic language, largely because its design philosophy eschews ambiguity. Ruby has exception handling features, like Java or Python, to make it easy to handle errors.

Standard library

Ruby's standard library is very extensive, including modules for YAML, JSON, XML, CGI sessions, RDF, and HTTP/DAV client. It also includes a library for unit testing, a debugger, and a profiler.

Implementations

The original Ruby interpreter, often referred to as Matz's Ruby Interpreter or MRI, was written in C by Matsumoto and the Ruby core team. Other implementations include JRuby, written in Java and fully integrated with the Java platform; Rubinius, written in a subset of Ruby and C++; and MacRuby/MRuby, which aim to enable Ruby to interface with the Objective-C runtime on Mac OS X.

Criticisms and shortcomings

While Ruby is often praised for its simplicity and ease of use, it has been criticized for its performance and scalability. However, many of these criticisms have been addressed with the release of Ruby 1.9 and subsequent versions, which have significantly improved the speed and efficiency of the language.

The Ruby programming language logo
The Ruby programming language logo

See Also