Ruby


Ruby is a free programming language . It is interpreted , object-oriented and multi- paradigm . The language has been standardized in Japan in 2011 ( JIS X 3017: 2011) 2 , and in 2012 by the International Organization for Standardization (ISO 30170: 2012) 3 .

History

Yukihiro “Matz” Matsumoto is the creator of Ruby. Frustrated by his experience in development Smalltalk and Lisp , he began designing a new language in 1993 under Emacs , then published a first version in 1995 under free license . It is continuing since the new versions.

Major version changes took place 4 :

  • the For version 1.2.0;
  • the For version 1.4.0;
  • the For version 1.6.0;
  • the For version 1.8.0;
  • the For version 1.9.1 (first stable version of branch 1.9) 5 ;
  • the For version 1.9.3 6 ;
  • the For version 2.0.0 7
  • the For version 2.1.0 8 .
  • August 19, 2015 for version 2.2.3.
  • On December 24, 2015 for version 2.3.0.

The latest stable release is 2.4.0, released on .

Since the arrival of an English language documentation, and web framework Ruby on Rails in 2004, Ruby has experienced a craze that has continued to grow until 2007 in the world of programming 9 .

Philosophy

Ruby is strongly object oriented and thus approaches the object paradigm of Smalltalk note 1 :

  • Any data is an object , including types ;
  • Any function is a method ;
  • Any variable is a reference to an object ;

Despite this exclusively object aspect , procedural programming is possible and frequent. Ruby uses a simple syntax , inspired by Eiffel and Ada 10 .

The language is often presented as avoiding as much as possible the bad surprises, according to the principle of least surprise 11 . But since it is not possible to avoid the surprise of all the users, Yukihiro Matsumoto specifies that it seeks especially to avoid its own surprise 12 . Thus, the more one knows the language, the more one knows the logic of its author, and the less one is astonished at the functionalities that one discovers.

Features

The main features are:

  • the object orientation omnipresent;
  • The garbage collector responsible for automatically releasing the memory ;
  • The exception handling system to handle exceptional errors;
  • The possibility of modifying the classes during the execution of the program , whether they are defined by the user or not;
  • The integration in its syntax of regular expressions ;
  • The blocks that serve as iterators and allow you to pass program pieces as a parameter;
  • the legacy single;
  • The inclusion of modules in classes , another way of conceiving multiple inheritance ( mixin );
  • The writing of extensions in C relatively simple;
  • numbers integers of unlimited size with automatic conversion when necessary 13 ;
  • The scope of variables defined by their form: var​is a local variable , @var​is an instance variable , @@var​is a class variable , $var​is a global variable , Var​is a constant .
  • The operating system independent threads ;
  • the reflection , that is to say the possibility for programs and objects to inspect themselves and change.

Implementations

The official interpreter , Ruby MRI , runs on many operating systems : UNIX , Linux , Microsoft Windows , MS-DOS , OS X , OS / 2 , ReactOS , AmigaOS , etc. It is published under the dual free license GNU GPL and the license Ruby 14 .

Ruby comes with irb , an interactive shell to thoroughly test the functioning of the language. There is a web version of irb to test Ruby in a browser 15 .

Since The development of Ruby (1.9) is based on the interpreter YARV writing Koichi Sasada 16 . This new shell offers a considerable performance gain 17 .

Besides YARV , there are several other interpreters Ruby 17 :

JRuby 18
It is written in Java and interprets directly from the source code written in Ruby.
XRuby
It converts Ruby code to Java bytecode and is faster on some performance benchmarks than version 1.8.5 of the official interpreter 19 .
Rubinius
A simplified virtual machine, inspired by Smalltalk-80 20 , implemented in Ruby itself.
Cardinal 21
An interpreter working under Parrot .
Gardens Point Ruby.NET
An interpreter running on the .NET framework 22 .
IronRuby
A compiler running on the DLR of the .NET framework 23 .
Ruby for .Net
A compiler running on the CLR of the .NET framework that has been abandoned in favor of IronRuby .
MacRuby
Implementation of Ruby 1.9 specific to OS X , running over the Objective-C 24 runtime , allowing native use of Cocoa components, unlike RubyCocoa bindings.

There is also a non-free solution, marketed by HipByte based on the work of the MacRuby project , called RubyMotion created by Laurent Sansonetti

Version 2.0 allows you to create graphical applications for OS X and IOS .

Embedded Interpreters

Ruby has a programming interface in C language that allows it to be integrated into other software . Ruby can be used in:

  • Apache with mod_ruby or Phusion Passenger to generate web pages in Ruby;
  • And PostgreSQL with PL / ruby to run Ruby commands to the database server .

The game software RPG Maker integrates in its versions XP and VX a library named RGSS, Ruby Game Scripting System allowing the use of scripts in Ruby.

Libraries

There are many function libraries that can be added to the language. The repository of these libraries is the Ruby Application Archive (RAA) 25 . It contains additional features for Ruby as class and module libraries, as well as extensions for using third-party libraries.

The RAA also contains software written in Ruby. Among these particular software found Rubygems which is a packaging tool and installation for Ruby extensions 26 . It allows you to quickly deploy libraries and Ruby programs.

The Rubyforge 27 website is also an important host of programs and libraries written in Ruby.

Examples

The classic Hello world :

Puts "Hello World!"

Use of objects:

# Everything is object, even numbers:
- 199 . Abs # 199
"ruby is cool" . Length # 12
"Rick" . Index "c" # 2
"Nice Day Is not It?" . Downcase . Split ( // ) . Out . Uniq . Join # "'acdeinsty"

Using Mixin and Heritage

Module AnimalSkills
 def eat
 puts "I'm eating!"
 End
 Def move
 puts "I'm moving!"
 End
 Def express ; Puts "I'm expressing!" End
end
Class Animal
 include AnimalSkills # mixin
 @@ name = 'an animal' # class variable
 def initialize size , weight , color # initialize instance variables
 @size = size . To_i
 @weight , @color = weight . To_i , color . To_s
 end
 Def describe
 puts "I'm # { @@ name } !"
 Puts "I'm # { @size } meter tall, I weigh # { @weight } kilograms and I'm" << @color
 end
end
Class Zebra < Animal #
 inheritance @@ name = 'a zebra' # redefined the class variable: now all animals are zebras!
 def initialize ( size , weight , color = 'black and white' ) # overload
 super # method call in the base class (Animal)
 end
end
Z = Zebra . New ( 1 , 50 )
z . Describe # => I'm a zebra! / I'm 1 meter tall, I weigh 50 kilograms and I'm black and white
z . Eat # => I'm eating!

Notes and references

Notes

  1. ↑ The main difference is that control structures (if-then-else, while, etc.) are not objects.

References

  1. ↑ Intro – D Programming Language 1.0 – Digital Mars  [ archive ] .
  2. ↑ JIS X 3017: 2011 – Programming languages ​​- Ruby  [ archive ] .
  3. ↑ ISO / IEC 30170: 2012 Information technology – Programming languages – Ruby  [ archive ] .
  4. ↑ Official FTP download site  [ archive ] .
  5. ↑ (en) Annonce de la version 1.9.1 [archive].
  6. ↑ Sortie de Ruby 1.9.3-p0 [archive].
  7. ↑ (en) Ruby 2.0.0-p0 is released [archive].
  8. ↑ (en) Ruby 2.1.0 is released [archive].
  9. ↑ Explication de la croissance [archive] sur le site officiel.
  10. ↑ (en) Ruby sur HOPL [archive], the History of Programming Languages.
  11. ↑ Definition of the PoLS on the Ruby Garden wiki  [ archive ] .
  12. ↑ ( en ) e-mail Re: A different perspective on Ruby sent by matz on May 26, 2005 on ruby-talk  [ archive ] .
  13. ↑ ( in ) Ruby-A Diamond of a Programming Language, Part 2 [ archive ] , article published on devx.com  [ archive ] .
  14. ↑ License text on the official website  [ archive ] .
  15. ↑ (en) Try Ruby! [archive] sur hobix.com.
  16. ↑ (en) The Ruby VM: Episode I [archive], interview de matz et de ko1 sur la machine virtuelle de Ruby.
  17. a et b (en) The Great Ruby Shootout [archive], comparaison des performances des principaux interpréteurs Ruby.
  18. ↑ Site officiel de JRuby [archive]
  19. ↑ (en) XRuby is faster than Ruby 1.8.5 in most benchmarks [archive].
  20. ↑ (en) Rubinius Interview [archive].
  21. ↑ Site du projet Cardinal [archive].
  22. ↑ (en) Ruby.NET – Integrating the Gardens Point Compiler [archive] par Huw Collingbourne.
  23. ↑ (en) http://www.ironruby.net/ [archive].
  24. ↑ (en) Site officiel de MacRuby [archive].
  25. ↑ Ruby Application Archive [archive].
  26. ↑ Official site of Rubygems  [ archive ] .
  27. ↑ RubyForge  [ archive ] .