PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/en/about/index.md

https://gitlab.com/suyesh/www.ruby-lang.org
Markdown | 249 lines | 192 code | 57 blank | 0 comment | 0 complexity | f0b9c452903a8ec866e74ad1d2334b85 MD5 | raw file
  1. ---
  2. layout: page
  3. title: "About Ruby"
  4. lang: en
  5. ---
  6. Wondering why Ruby is so popular? Its fans call it a beautiful, artful
  7. language. And yet, they say its handy and practical. What gives?
  8. {: .summary}
  9. ### The Ideals of Rubys Creator
  10. Ruby is a language of careful balance. Its creator, [Yukihiro Matz
  11. Matsumoto][matz], blended parts of his favorite languages (Perl, Smalltalk,
  12. Eiffel, Ada, and Lisp) to form a new language that balanced functional
  13. programming with imperative programming.
  14. He has often said that he is trying to make Ruby natural, not simple,
  15. in a way that mirrors life.
  16. Building on this, he adds:
  17. > Ruby is simple in appearance, but is very complex inside, just like
  18. > our human body<sup>[1](#fn1)</sup>.
  19. ### About Rubys Growth
  20. Since its public release in 1995, Ruby has drawn devoted coders
  21. worldwide. In 2006, Ruby achieved mass acceptance. With active user
  22. groups formed in the worlds major cities and Ruby-related conferences
  23. filled to capacity.
  24. ![Graph courtesy of
  25. Gmane.](http://gmane.org/plot-rate.php?group=gmane.comp.lang.ruby.general&amp;width=320&amp;height=160&amp;title=Ruby-Talk+Activity
  26. "Graph courtesy of Gmane."){: style="padding-left:8px;"}
  27. {: style="float:right"}
  28. Ruby-Talk, the primary [mailing list](/en/community/mailing-lists/) for
  29. discussion of the Ruby language, climbed to an average of 200 messages
  30. per day in 2006. It has dropped in recent years as the size of the
  31. community pushed discussion from one central list into many smaller
  32. groups.
  33. Ruby is ranked among the top 10 on most of the indices that measure
  34. the growth and popularity of programming languages worldwide
  35. (such as the [TIOBE index][tiobe]). Much of the growth is attributed to the
  36. popularity of software written in Ruby, particularly the
  37. [Ruby on Rails][ror] web framework.
  38. Ruby is also [completely free]({{ site.license.url }}). Not only free of charge, but
  39. also free to use, copy, modify, and distribute.
  40. ### Seeing Everything as an Object
  41. Initially, Matz looked at other languages to find an ideal syntax.
  42. Recalling his search, he said, I wanted a scripting language that was
  43. more powerful than Perl, and more object-oriented than
  44. Python<sup>[2](#fn2)</sup>.
  45. In Ruby, everything is an object. Every bit of information and code can
  46. be given their own properties and actions. Object-oriented programming
  47. calls properties by the name *instance variables* and actions are known
  48. as *methods*. Rubys pure object-oriented approach is most commonly
  49. demonstrated by a bit of code which applies an action to a number.
  50. {% highlight ruby %}
  51. 5.times { print "We *love* Ruby -- it's outrageous!" }
  52. {% endhighlight %}
  53. In many languages, numbers and other primitive types are not objects.
  54. Ruby follows the influence of the Smalltalk language by giving methods
  55. and instance variables to all of its types. This eases ones use of
  56. Ruby, since rules applying to objects apply to all of Ruby.
  57. ### Rubys Flexibility
  58. Ruby is seen as a flexible language, since it allows its users to freely
  59. alter its parts. Essential parts of Ruby can be removed or redefined, at
  60. will. Existing parts can be added upon. Ruby tries not to restrict the
  61. coder.
  62. For example, addition is performed with the plus (`+`) operator. But, if
  63. youd rather use the readable word `plus`, you could add such a method
  64. to Rubys builtin `Numeric` class.
  65. {% highlight ruby %}
  66. class Numeric
  67. def plus(x)
  68. self.+(x)
  69. end
  70. end
  71. y = 5.plus 6
  72. # y is now equal to 11
  73. {% endhighlight %}
  74. Rubys operators are syntactic sugar for methods. You can redefine them
  75. as well.
  76. ### Blocks: a Truly Expressive Feature
  77. Rubys block are also seen as a source of great flexibility. A
  78. programmer can attach a closure to any method, describing how that
  79. method should act. The closure is called a *block* and has become one of
  80. the most popular features for newcomers to Ruby from other imperative
  81. languages like PHP or Visual Basic.
  82. Blocks are inspired by functional languages. Matz said, in Ruby
  83. closures, I wanted to respect the Lisp culture<sup>[3](#fn3)</sup>.
  84. {% highlight ruby %}
  85. search_engines =
  86. %w[Google Yahoo MSN].map do |engine|
  87. "http://www." + engine.downcase + ".com"
  88. end
  89. {% endhighlight %}
  90. In the above code, the block is described inside the `do ... end`
  91. construct. The `map` method applies the block to the provided list of
  92. words. Many other methods in Ruby leave a hole open for a coder to write
  93. their own block to fill in the details of what that method should do.
  94. ### Ruby and the Mixin
  95. Unlike many object-oriented languages, Ruby features single inheritance
  96. only, **on purpose**. But Ruby knows the concept of modules (called
  97. Categories in Objective-C). Modules are collections of methods.
  98. Classes can mixin a module and receive all its methods for free. For
  99. example, any class which implements the `each` method can mixin the
  100. `Enumerable` module, which adds a pile of methods that use `each` for
  101. looping.
  102. {% highlight ruby %}
  103. class MyArray
  104. include Enumerable
  105. end
  106. {% endhighlight %}
  107. Generally, Rubyists see this as a much clearer way than multiple
  108. inheritance, which is complex and can be too restrictive.
  109. ### Rubys Visual Appearance
  110. While Ruby often uses very limited punctuation and usually prefers
  111. English keywords, some punctuation is used to decorate Ruby. Ruby needs
  112. no variable declarations. It uses simple naming conventions to denote
  113. the scope of variables.
  114. * `var` could be a local variable.
  115. * `@var` is an instance variable.
  116. * `$var` is a global variable.
  117. These sigils enhance readability by allowing the programmer to easily
  118. identify the roles of each variable. It also becomes unnecessary to use
  119. a tiresome `self.` prepended to every instance member.
  120. ### Beyond the Basics
  121. Ruby has a wealth of other features, among which are the following:
  122. * Ruby has exception handling features, like Java or Python, to make it
  123. easy to handle errors.
  124. * Ruby features a true mark-and-sweep garbage collector for all Ruby
  125. objects. No need to maintain reference counts in extension libraries.
  126. As Matz says, This is better for your health.
  127. * Writing C extensions in Ruby is easier than in Perl or Python, with a
  128. very elegant API for calling Ruby from C. This includes calls for
  129. embedding Ruby in software, for use as a scripting language. A SWIG
  130. interface is also available.
  131. * Ruby can load extension libraries dynamically if an OS allows.
  132. * Ruby features OS independent threading. Thus, for all platforms on
  133. which Ruby runs, you also have multithreading, regardless of if the OS
  134. supports it or not, even on MS-DOS!
  135. * Ruby is highly portable: it is developed mostly on GNU/Linux, but
  136. works on many types of UNIX, Mac OS X, Windows 95/98/Me/NT/2000/XP,
  137. DOS, BeOS, OS/2, etc.
  138. ### Other Implementations of Ruby
  139. Ruby, as a language, has a few different implementations.
  140. This page has been discussing the reference implementation, in the
  141. community often referred to as **MRI** (Matzs Ruby Interpreter)
  142. or **CRuby** (since it is written in C), but there are also others.
  143. They are often useful in certain situations, provide extra
  144. integration to other languages or environments, or have special features
  145. that MRI doesnt.
  146. Heres a list:
  147. * [JRuby][jruby] is Ruby atop the JVM (Java Virtual Machine), utilizing the
  148. JVMs optimizing JIT compilers, garbage collectors, concurrent
  149. threads, tool ecosystem, and vast collection of libraries.
  150. * [Rubinius][rubinius] is Ruby written in Ruby. Built on top of LLVM,
  151. Rubinius sports a nifty virtual machine that other languages are being
  152. built on top of, too.
  153. * [MacRuby][macruby] is a Ruby thats tightly integrated with Apples Cocoa
  154. libraries for Mac OS X, allowing you to write desktop applications
  155. with ease.
  156. * [mruby][mruby] is a lightweight implementation of the Ruby language
  157. that can be linked and embedded within an application.
  158. Its development is led by Rubys creator Yukihiro Matz Matsumoto.
  159. * [IronRuby][ironruby] is an implementation tightly integrated with the .NET
  160. Framework.
  161. * [MagLev][maglev] is a fast, stable, Ruby implementation with integrated
  162. object persistence and distributed shared cache.
  163. * [Cardinal][cardinal] is a Ruby compiler for [Parrot][parrot] Virtual Machine
  164. (Perl 6).
  165. Some of those implementations, including MRI, follow the guidelines of
  166. [RubySpec][rubyspec], a complete executable specification for the Ruby
  167. programming language.
  168. ### References
  169. <sup>1</sup> Matz, speaking on the Ruby-Talk mailing list, [May 12th,
  170. 2000][blade].
  171. {: #fn1}
  172. <sup>2</sup> Matz, in [An Interview with the Creator of Ruby][linuxdevcenter], Nov.
  173. 29th, 2001.
  174. {: #fn2}
  175. <sup>3</sup> Matz, in [Blocks and Closures in Ruby][artima], December 22nd,
  176. 2003.
  177. {: #fn3}
  178. [matz]: http://www.rubyist.net/~matz/
  179. [blade]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773
  180. [ror]: http://rubyonrails.org/
  181. [linuxdevcenter]: http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html
  182. [artima]: http://www.artima.com/intv/closures2.html
  183. [tiobe]: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  184. [jruby]: http://jruby.org
  185. [rubinius]: http://rubini.us
  186. [macruby]: http://www.macruby.org
  187. [mruby]: http://www.mruby.org/
  188. [ironruby]: http://www.ironruby.net
  189. [maglev]: http://ruby.gemstone.com
  190. [cardinal]: https://github.com/parrot/cardinal
  191. [parrot]: http://parrot.org
  192. [rubyspec]: http://rubyspec.org