About Ruby

Wondering why Ruby is so popular? His fans call him a beautiful, skillful tongue. And at the same time they say that it is comfortable and practical. What outweighs?

The ideals of the creator of Ruby

Ruby is a carefully balanced language. Its creator, Yukihiro Matsumoto (also known as “Matz”), combined parts of his favorite languages ​​(Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balances the functional programming paradigm with imperative programming principles.

He often said that he was “trying to make Ruby a natural, but not simple” language that reflects life.

Based on this, he adds: Ruby is simple in appearance, but very complex inside, like the human body1.

The rise of Ruby

Since the release of the public version in 1995, Ruby has attracted the attention of programmers from all over the world. In 2006, Ruby gained mainstream acceptance. Ruby user groups are active in major cities around the world, and Ruby conferences are packed to capacity.

Ruby-Talk, the main Ruby language discussion mailing list, averaged 200 messages daily in 2006. In recent years, this number has decreased, as the community began to use several thematic mailing lists instead of one general one.

The TIOBE index, which measures the rise in popularity of programming languages, places Ruby in the top ten of the most widely accepted programming languages. Much of the language’s rise in popularity is attributed to the popularity of software written in Ruby, especially Ruby on Rails, a framework for developing web applications.

Ruby is also completely open. Open for free use, modification, copying and distribution.

Everything in Ruby is an object.

Early on, Matz looked at other languages ​​in search of the perfect syntax. Recalling his research, he said, “I needed a scripting language that was more powerful than Perl and more object-oriented than Python2.”

In Ruby, everything is an object. Each piece of information or code can have its own properties and actions. In object-oriented programming, properties are called object variables, and actions are called methods. Ruby’s purest object-oriented approach can be demonstrated with a couple of lines of code that operate on a number.

5.times { print “We love Ruby! Ruby is great!” }

In many languages, numbers and other primitive data types are not objects. Ruby, influenced by the Smalltalk language, allows you to set methods and object variables for all data types. This simplifies the use of Ruby, as the rules that apply to objects apply to all of Ruby.

Flexibility of Ruby

Ruby is a very flexible language, as it allows its users to freely change parts of it. Core parts of Ruby can be removed or redefined as desired. And existing parts can be changed. Ruby tries not to limit the user in anything.

For example, addition is performed by the plus (+) operation. But, if you want to use the more readable word plus for this, you can add such a method directly to Numeric, an internal class of the Ruby language.

class Numeric

Operators in Ruby are syntactic sugar for methods. You can also override them.

Blocks are a truly expressive design

Blocks in Ruby are also a great source of flexibility. The programmer can add a closure to any method, describing how the method should act. A closure is a block that is one of the most popular constructs for those who came to the world of Ruby from the world of imperative programming languages ​​such as PHP or Visual Basic.

The creation of blocks was inspired by functional programming languages. Matz said, “I wanted to pay homage to Lisp3 culture with Ruby closures.”

search_engines=%w[Google Yahoo MSN].map 
do |engine|"http://www." + engine.downcase + ".com"


In the code above, the block is described inside the do … end construct. The map method applies a block of code to the presented list of words. Many other methods in Ruby leave a path open for the programmer to write their own block of code that tells the method in detail what it should do.

Ruby and Mixins

Unlike many object-oriented languages, Ruby intentionally provides only single inheritance. But Ruby also provides the concept of modules (called “categories” in Objective-C). Modules are collections of methods.

Classes are free to intervene in a module and get all of its methods. For example, any class that implements the each method can mix in the Enumerable module, which will add a bunch of methods that use each to create loops.

class MyArray
  include Enumerable

Basically, rubists find this more transparent than multiple inheritance, which can be quite complex and have some limitations.

Visual representation of Ruby

Since punctuation is often quite rare in Ruby and English is usually used as keywords, some punctuation marks are used to decorate Ruby. Ruby doesn’t need to declare variables. It uses simple naming conventions to separate variable scopes.

var - can be a local variable.
@var is an object variable.
$var is a global variable.

This symbology enhances readability by allowing the programmer to easily identify the role of each variable. It also avoids the tedious self. for each object.

Beyond the basics

Ruby is full of other features and constructs, and here are some of them:

Ruby has exception handling constructs, like Java or Python, that make it easier to deal with errors.

Ruby provides a true mark-and-sweep garbage collector for all Ruby objects. No need to manually track the number of links in third-party libraries. As Matz says, “It’s better for your health.”

Writing C extensions in Ruby is easier than in Perl or Python, with a very elegant API for calling Ruby from C. It includes calls to embed Ruby in software to use it as a scripting language. A SWIG interface is also available.

Ruby can load third-party libraries dynamically if the operating system allows it.

Ruby implements operating system-independent threads. Thus, on any platform where you run Ruby, you can also use multithreading, whether that system supports threads or not. You can use multithreading even in MS-DOS!

Ruby is highly portable: it was developed mostly on GNU/Linux, but it runs on many types of UNIX, macOS, Windows, DOS, BeOS, OS/2, and so on.

Other implementations of Ruby

Ruby as a language has several different implementations. This site is about implementing MRI (“Matz’s Ruby Interpreter” – Matz’s Ruby interpreter) or CRuby, but there are several others. They are very useful in a variety of situations, provide great integration with other languages ​​or environments, or have features not found in MRI.

List of implementations:

  • JRuby is Ruby implemented on the JVM (Java Virtual Machine), using an optimized JIT compiler, garbage collector, native threads, a tooling ecosystem, and a huge number of JVM libraries.
  • Rubinius is “Ruby written in Ruby”. It is implemented on the basis of LLVM – an elegant virtual machine, on which other well-known languages ​​are created.
  • mruby is a lightweight implementation of Ruby that can be plugged in and built into an application. The development of mruby is led by the creator of the Ruby language, Yukihiro Matsumoto, alias Matz.
  • IronRuby is an implementation “tightly integrated with the .NET Framework”.
  • MagLev is “a fast, stable implementation of Ruby with integrated object persistence and distributed open cache.”
  • Cardinal is “the Ruby compiler for the Parrot virtual machine” (Perl 6).

Leave a Reply

Your email address will not be published. Required fields are marked *