Ruby

format_list_bulleted Contenido keyboard_arrow_down
ImprimirCitar

Ruby is an object-oriented, reflective, interpreted programming language, created by the Japanese programmer Yukihiro "Matz" Matsumoto, who began working on Ruby in 1993, and publicly introduced it in 1995. It combines a Python and Perl-inspired syntax with Smalltalk-like object-oriented programming features. It also shares functionality with other programming languages such as Lisp, Lua, Dylan and CLU. Ruby is a single-pass interpreted programming language and its official implementation is distributed under a free software license.

History

The language was created by Yukihiro "Matz" Matsumoto, who began working on Ruby on February 24, 1993, and introduced it to the public in 1995. In Matsumoto's circle of friends, it was given the name Ruby.) as a joke alluding to the Perl programming language (perla in English). The latest stable version from the 1.8 branch is 1.8.7_p248, from the 1.9 branch is 1.9.2_p180. The version in 1.9 that incorporates substantial improvements in the performance of the language, which are expected to be reflected in the next stable production version of the language, Ruby 1.9.0.1 Performance differences between the current Ruby implementation (1.8.6) and other languages More entrenched programming methods have led to the development of various virtual machines for Ruby. Among these are JRuby, an attempt to bring Ruby to the Java platform, and Rubinius, a modeled interpreter based on Smalltalk's virtual machines. Major developers have supported the virtual machine provided by the YARV project, which was merged into the Ruby source tree on December 31, 2006, and was released as Ruby 1.9.

Philosophy

Yukihiro Matsumoto, the creator of Ruby

The creator of the language, Yukihiro "Matz" Matsumoto, has said that Ruby is designed for developer productivity and fun, following the principles of a good user interface.He argues that system design needs to emphasize human rather than machine needs:

Often people, especially computer engineers, focus on machines. They think, "Doing this, the machine will work faster. By doing this, the machine will work more efficiently. Doing this..." They are focused on machines, but we really need to focus on people, how they make programs or how they handle applications on computers. We're the bosses. They're the slaves.

Ruby has been assumed to follow the principle of least surprise, which would mean that the language should behave in such a way as to minimize confusion for experienced users. However, Matz himself has stated that his main goal was to make a language that would be fun for himself, minimizing programming work and possible confusion, and that he did not apply the principle of least surprise to Ruby's design. However, the phrase has been associated with the language and has been a source of controversy, as the uninitiated may assume that Ruby's features are similar to features of other known languages. In a May 2005 discussion on the comp.lang.ruby newsgroup, Matz tried to distance Ruby from the aforementioned philosophy, explaining that any design choice will surprise someone, and that he uses a personal standard for evaluating The surprise. If that personal standard remains consistent, there will be few surprises for those familiar with the standard.

Matz defined it this way in an interview:

Everyone has a personal past. Someone may come from Python, another Perl, and may be surprised by different aspects of language. Then they could say 'I am surprised by this characteristic of language, so Ruby violates the principle of the least surprise.' Wait, wait. The principle of the least surprise is not just for you. The principle of the least surprise means the principle of 'my' less surprise. And it means the principle of the least surprise after you learn well Ruby. For example, I was a C++ programmer before I started designing Ruby. I programmed exclusively on C++ for two or three years. And after two years of programming in C++, I was still surprised.

Semantics

Ruby is object-oriented: all data types are objects, including classes and types that other languages define as primitives (such as integers, booleans, and nil). Every function is a method. Variables are always references to objects, not the objects themselves. Ruby supports inheritance with dynamic binding, mixins, and singleton methods (owned and defined by a single instance rather than defined by the class). Although Ruby does not support multiple inheritance, classes can import modules as mixins. It supports procedural syntax, but all methods defined outside the scope of an object are really methods of the Object class. Since this class is the parent of all the others, the changes are visible to all classes and objects.

Ruby has been described as a multi-paradigm programming language: it allows programming procedurally (defining functions and variables outside of classes by making them part of the root Object), object-oriented (everything is an object), or functionally (has functions anonymous, closures, and continuations; all statements have values, and functions return the last evaluation). It supports introspection, reflection, and metaprogramming, as well as support for shell-managed threads. Ruby is dynamically typed, and supports type polymorphism (allows subclasses to be addressed using the parent class's interface). Ruby does not require function polymorphism (function overloading) as it is dynamically typed (the parameters of a function can be of a different type in each call, the function being in charge of determining the type and acting accordingly).

According to the Ruby FAQ, "If you like Perl, you will like Ruby and its syntax. If you like Smalltalk, you will like Ruby and its semantics. If you like Python, the vast design difference between Python and Ruby/Perl may or may not win you over.

Features

  • Orientated to objects
  • Four levels of variable range: global, class, instance and local.
  • Handling of exceptions
  • iterators and closures or closures (passing code blocks)
  • native regular expressions similar to those of Perl at language level
  • Possibility of redefining operators (overload of operators)
  • automatic garbage collection
  • Highly portable
  • Simultaneous execution threads on all platforms using Green threadsor not managed by the operating system.
  • Dynamic load of shared DLL/library in most of the platforms
  • Introspection, Reflection and Metaprogramming
  • Wide standard library
  • Supports injection of units
  • Supports alteration of objects in time of execution
  • and generators

Ruby currently does not have full Unicode support, despite having partial support for UTF-8.

Interaction

The official Ruby distribution includes irb (Interactive Ruby Shell), an interactive command line interpreter that can be used to quickly test code. The following code snippet represents a sample session using irb:

$ irbirb(main(c):001:0 Fuck! "Hello world"Hi. world= 2005 nilirb(main(c):002:0 1+2= 2005 3

Syntax

Ruby's syntax is similar to that of Perl or Python. The definition of classes and methods is defined by keywords. However, in Perl, variables do not take prefixes. When used, a prefix indicates the scope of the variables. The biggest difference with C and Perl is that keywords are used to define blocks of code without braces. Line breaks are significant and are interpreted as the end of a statement; the semicolon has the same use. Unlike in Python, the indentation is not significant.

One of the differences between Ruby and Python and Perl is that Ruby keeps all its private instance variables inside classes and only exposes them via accessor methods (attr_writer, attr_reader, etc.). Unlike the get and set methods of other languages such as C++ or Java, accessor methods in Ruby can be written with a single line of code. Since calling these methods does not require the use of parentheses, it is trivial to change an instance variable in a function without touching a single line of code or refactoring that code. Python property descriptors are similar but have a downside in the development process. If one starts in Python using a publicly exposed variable instance and later changes the implementation to use a private variable instance exposed via a property descriptor, the code inside the class will need to be adjusted to use the private variable instead of public property. Ruby removes this design decision by forcing all instance variables to be private, but it also provides an easy way to declare set and get methods. This maintains the principle that in Ruby you cannot access the internal members of a class from outside the class; instead a message is passed (a method is called) to the class and it receives a response.

License

The interpreter and libraries are licensed dually (inseparably) under the free software licenses GPL and the Ruby License.

As of version 1.9.3, a dual license is opted for under the two-clause BSD licenses and the Ruby Public License.

Contenido relacionado

Apollon (P2P Client)

Apollon is a peer-to-peer file sharing network client for the KDE project, distributed under the terms of the GNU...

International Telegraph and Telephone Consultative Committee

CCITT stands for Consultative Committee for International Telegraphy and Telephone former name of the telecommunications standardization committee within the...

DCE

The Data Circuit-terminating Equipment in English: Data Circuit-terminating Equipment also known as Data Communication Equipment Data is that device that...
Más resultados...
Tamaño del texto:
undoredo
format_boldformat_italicformat_underlinedstrikethrough_ssuperscriptsubscriptlink
save