Ruby (programming language): Difference between revisions

Content deleted Content added
Fixing Matsumoto link.
added example, restructured a bit
Line 2:
'''Ruby''' is a purely [[object-oriented]] [[programming language]] originally developed for [[scripting programming language|scripting]]. It combines syntax inspired by [[Ada programming language|Ada]] and [[Perl programming language|Perl]] with [[Smalltalk programming language|Smalltalk]]-like [[object oriented]] features, and also shares some features with [[Python programming language|Python]], [[Lisp programming language|Lisp]] and [[CLU programming language|CLU]].
 
Ruby currently has only one implementation, the Ruby [[interpreter (computer software)|interpreter]], although efforts are underway to implement a Ruby front end (called "Cardinal") for the [[Parrot virtual machine]] is in planning. It has been ported to many platforms, including [[Unix]], Microsoft Windows, [[DOS]], [[Mac OS X]], [[OS/2]], [[Amiga]], and many more.
 
Ruby is '''purely object-oriented''': every bit of data is an object, including types that are designated "primitive" in impureother languages, for example integers. Every function is a method. Named This is similar to Smalltalk but unlike [[Java programming language|Java]]. Every named valuevalues (variable namevariables) indesignate a Ruby program designates a referencereferences to an objectobjects, not the objectobjects itselfthemselves. Ruby supports [[inheritance (object-oriented programming)|inheritances]] with [[dynamic dispatch]], [[mixin]]s, and [[singleton method]]s (belonging to an [[instance]] rather than a class). Though Ruby does not support [[multiple inheritance]], but classes can import [[modules]] as mixins. Although Ruby can haveWhile procedural syntax is possible, everything in Ruby is an object, in the sense of Smalltalk, not Perl or Python. Anything done in Ruby procedurally (ie. outside of the scope of a particular object) is actually done to the Object primative,class. modifyingSince allthis classesclass andis objectsparent soto theyevery canother useclass, itthe changes become visible to all classes and objects.
Ruby has many useful features. Ruby also supports [[Operator overloading]] and [[Exception handling]]. Currently, Ruby lacks [[Unicode]] support. Ruby has [[Iterator]]s (which resemble those in [[CLU programming language|CLU]] and [[Sather programming language|Sather]]). Ruby supports [[Closure (programming)|Closure]]s (also found in [[Smalltalk programming language|Smalltalk]] and many [[functional programming language]]s). Ruby has native, syntactic support for [[Perl]]-like [[regular expression]]s at the language level (not merely in [[library (software)|libraries]], as in Python or many other languages). Ruby supports [[automatic garbage collection]] and [[DLL|Dynamic library]] loading/linking (depending on the architecture) on [[Microsoft Windows]]. Ruby has been ported to many platforms, including [[Unix]], Microsoft Windows, [[DOS]], [[Mac OS X]], [[OS/2]], [[Amiga]], and many more.
 
The language was created by [[Yukihiro Matsumoto|Yukihiro "Matz" Matsumoto]], who started working on Ruby on February 24, [[1993]]. and released it to the public in [[1995]]. The current stable version is 1.8.1. (as of February 2004). Note that the name is not an [[acronym]] -- it is actually a [[pun]] on [[Perl]]. According to the author, he designed Ruby to follow the ''[[principle of least surprise]]'' (POLS), meaning that the language should be free from the traps and inconsistencies that plague other languages.
Ruby is purely object-oriented: every bit of data is an object, including types that are designated "primitive" in impure languages. Every function is a method. This is similar to Smalltalk but unlike [[Java programming language|Java]]. Every named value (variable name) in a Ruby program designates a reference to an object, not the object itself. Ruby supports [[inheritance (object-oriented programming)|inheritances]] with [[dynamic dispatch]], [[mixin]]s, and [[singleton method]]s. Ruby does not support multiple inheritance, but classes can import modules as mixins. Although Ruby can have procedural syntax, everything in Ruby is an object, in the sense of Smalltalk, not Perl or Python. Anything done in Ruby procedurally (ie. outside of the scope of a particular object) is actually done to the Object primative, modifying all classes and objects so they can use it.
 
From the Ruby [[FAQ]]: ''"If you like Perl, you will like Ruby and be right at home with its syntax. If you like Smalltalk, you will like Ruby and be right at home with its semantics. If you like Python, you may or may not be put off by the huge difference in design philosophy between Python and Ruby/Perl."''
The language was created by [[Yukihiro Matsumoto|Yukihiro "Matz" Matsumoto]] on February 24, [[1993]]. The current stable version is 1.8.1. Note that the name is not an [[acronym]]--it is actually a [[pun]] on [[Perl]]. According to the author, he designed Ruby to follow the ''[[principle of least surprise]]'' (POLS), meaning that the language should be free from the traps and inconsistencies that plague other languages.
 
From the Ruby [[FAQ]]: ''If you like Perl, you will like Ruby and be right at home with its syntax. If you like Smalltalk, you will like Ruby and be right at home with its semantics. If you like Python, you may or may not be put off by the huge difference in design philosophy between Python and Ruby/Perl.''
 
Ruby is distributed disjointly under the [[Free software|free]] and [[open source]] licences [[GNU General Public License|GPL]] and Ruby License [http://www.ruby-lang.org/en/LICENSE.txt].
 
==Features==
*pure [[object-oriented|object-orientation]]
*[[exception handling]]
*[[iterator]]s and [[closures]] (based on passable blocks of code)
*native, [[Perl]]-like [[regular expression]] at the language level
*[[operator overloading]]
*[[automatic garbage collection]]
*[[multithreading]]
*[[DLL]] loading on [[Microsoft Windows]]
 
Ruby currently lacks support for [[Unicode]].
 
 
== Examples ==
Line 29 ⟶ 40:
>> "John".swapcase
=> "jOHN"
 
 
>> #Arrays
?>> [11, 5, 7, 2, 13, 3].sort
=> [2, 3, 5, 7, 11, 13]
 
Line 38 ⟶ 48:
=> [13, 11, 7, 5, 3, 2]
 
>> #Iterators (the code block {...} is passed to "collect")
>> ["Ruby is cool!"].collect { |x| x.length }
=> [4, 2, 5]
 
# Execute the following block of code 10 times