CINXE.COM
About Ruby
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>About Ruby</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta itemprop="image" content="https://www.ruby-lang.org/images/header-ruby-logo@2x.png"> <meta name="description" content=""> <link rel="stylesheet" type="text/css" href="/stylesheets/normalize.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/main.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/pygments.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/mobile.css"> <link rel="stylesheet" type="text/css" href="/stylesheets/print.css"> <link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic&subset=latin,cyrillic,greek,vietnamese' rel='stylesheet' type='text/css'> <link rel="canonical" href="https://www.ruby-lang.org/en/about/"> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"> <link href="/en/feeds/news.rss" rel="alternate" title="Recent News (RSS)" type="application/rss+xml"> <script type="text/javascript" src="/javascripts/jquery.min.js"></script> <script type="text/javascript" src="/javascripts/page.js"></script> </head> <body> <div id="header"> <div id="header_content" class="container"> <a href="/en/"> <h1>Ruby</h1> <h2>A Programmer's Best Friend</h2> </a> <div class="site-links"> <a href="/en/" class="home">Home</a> <a href="/en/downloads/">Downloads</a> <a href="/en/documentation/">Documentation</a> <a href="/en/libraries/">Libraries</a> <a href="/en/community/">Community</a> <a href="/en/news/">News</a> <a href="/en/security/">Security</a> <a href="/en/about/">About Ruby</a> <a href="#" class="menu selected">Menu</a> </div> <div id="search-box"> <form id="search-form" action="https://www.google.com/cse"> <table class="fieldset"> <tr> <td> <input class="field" type="text" name="q" size="31" style="background: white url(//www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) left no-repeat" onfocus="this.style.background='white'" onblur="if (/^\s*$/.test(this.value)) this.style.background='white url(//www.google.com/coop/intl/en/images/google_custom_search_watermark.gif) left no-repeat'"/> </td> <td> <input type="hidden" name="cx" value="013598269713424429640:g5orptiw95w" /> <input type="hidden" name="ie" value="UTF-8" /> <input class="button" type="submit" name="sa" value="Search" /> </td> </tr> </table> </form> </div> </div> </div> <div id="page"> <div id="main-wrapper" class="container"> <div id="main"> <div id="content-wrapper"> <h1>About Ruby</h1> <div id="content"> <p class="summary">Wondering why Ruby is so popular? Its fans call it a beautiful, artful language. And yet, they say it’s handy and practical. What gives?</p> <h3>The Ideals of Ruby’s Creator</h3> <p>Ruby is a language of careful balance. Its creator, <a href="http://www.rubyist.net/~matz/">Yukihiro “Matz” Matsumoto</a>, blended parts of his favorite languages (Perl, Smalltalk, Eiffel, Ada, and Lisp) to form a new language that balanced functional programming with imperative programming.</p> <p>He has often said that he is “trying to make Ruby natural, not simple,” in a way that mirrors life.</p> <p>Building on this, he adds:</p> <blockquote> <p>Ruby is simple in appearance, but is very complex inside, just like our human body<sup><a href="#fn1">1</a></sup>.</p> </blockquote> <h3>About Ruby’s Growth</h3> <p>Since its public release in 1995, Ruby has drawn devoted coders worldwide. In 2006, Ruby achieved mass acceptance. With active user groups formed in the world’s major cities and Ruby-related conferences filled to capacity.</p> <p>Ruby-Talk, the primary <a href="/en/community/mailing-lists/">mailing list</a> for discussion of the Ruby language, climbed to an average of 200 messages per day in 2006. It has dropped in recent years as the size of the community pushed discussion from one central list into many smaller groups.</p> <p>Ruby is ranked among the top 10 on most of the indices that measure the growth and popularity of programming languages worldwide (such as the <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">TIOBE index</a>). Much of the growth is attributed to the popularity of software written in Ruby, particularly the <a href="http://rubyonrails.org/">Ruby on Rails</a> web framework.</p> <p>Ruby is also <a href="/en/about/license.txt">completely free</a>. Not only free of charge, but also free to use, copy, modify, and distribute.</p> <h3>Seeing Everything as an Object</h3> <p>Initially, Matz looked at other languages to find an ideal syntax. Recalling his search, he said, “I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python<sup><a href="#fn2">2</a></sup>.”</p> <p>In Ruby, everything is an object. Every bit of information and code can be given their own properties and actions. Object-oriented programming calls properties by the name <em>instance variables</em> and actions are known as <em>methods</em>. Ruby’s pure object-oriented approach is most commonly demonstrated by a bit of code which applies an action to a number.</p> <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="mi">5</span><span class="p">.</span><span class="nf">times</span> <span class="p">{</span> <span class="nb">print</span> <span class="s2">"We *love* Ruby -- it's outrageous!"</span> <span class="p">}</span></code></pre></figure> <p>In many languages, numbers and other primitive types are not objects. Ruby follows the influence of the Smalltalk language by giving methods and instance variables to all of its types. This eases one’s use of Ruby, since rules applying to objects apply to all of Ruby.</p> <h3>Ruby’s Flexibility</h3> <p>Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Essential parts of Ruby can be removed or redefined, at will. Existing parts can be added upon. Ruby tries not to restrict the coder.</p> <p>For example, addition is performed with the plus (<code class="language-plaintext highlighter-rouge">+</code>) operator. But, if you’d rather use the readable word <code class="language-plaintext highlighter-rouge">plus</code>, you could add such a method to Ruby’s builtin <code class="language-plaintext highlighter-rouge">Numeric</code> class.</p> <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">Numeric</span> <span class="k">def</span> <span class="nf">plus</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="nb">self</span><span class="p">.</span><span class="nf">+</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">end</span> <span class="k">end</span> <span class="n">y</span> <span class="o">=</span> <span class="mi">5</span><span class="p">.</span><span class="nf">plus</span> <span class="mi">6</span> <span class="c1"># y is now equal to 11</span></code></pre></figure> <p>Ruby’s operators are syntactic sugar for methods. You can redefine them as well.</p> <h3>Blocks: a Truly Expressive Feature</h3> <p>Ruby’s block are also seen as a source of great flexibility. A programmer can attach a closure to any method, describing how that method should act. The closure is called a <em>block</em> and has become one of the most popular features for newcomers to Ruby from other imperative languages like PHP or Visual Basic.</p> <p>Blocks are inspired by functional languages. Matz said, “in Ruby closures, I wanted to respect the Lisp culture<sup><a href="#fn3">3</a></sup>.”</p> <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="n">search_engines</span> <span class="o">=</span> <span class="sx">%w[Google Yahoo MSN]</span><span class="p">.</span><span class="nf">map</span> <span class="k">do</span> <span class="o">|</span><span class="n">engine</span><span class="o">|</span> <span class="s2">"http://www."</span> <span class="o">+</span> <span class="n">engine</span><span class="p">.</span><span class="nf">downcase</span> <span class="o">+</span> <span class="s2">".com"</span> <span class="k">end</span></code></pre></figure> <p>In the above code, the block is described inside the <code class="language-plaintext highlighter-rouge">do ... end</code> construct. The <code class="language-plaintext highlighter-rouge">map</code> method applies the block to the provided list of words. Many other methods in Ruby leave a hole open for a coder to write their own block to fill in the details of what that method should do.</p> <h3>Ruby and the Mixin</h3> <p>Unlike many object-oriented languages, Ruby features single inheritance only, <strong>on purpose</strong>. But Ruby knows the concept of modules (called Categories in Objective-C). Modules are collections of methods.</p> <p>Classes can mixin a module and receive all its methods for free. For example, any class which implements the <code class="language-plaintext highlighter-rouge">each</code> method can mixin the <code class="language-plaintext highlighter-rouge">Enumerable</code> module, which adds a pile of methods that use <code class="language-plaintext highlighter-rouge">each</code> for looping.</p> <figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">class</span> <span class="nc">MyArray</span> <span class="kp">include</span> <span class="no">Enumerable</span> <span class="k">end</span></code></pre></figure> <p>Generally, Rubyists see this as a much clearer way than multiple inheritance, which is complex and can be too restrictive.</p> <h3>Ruby’s Visual Appearance</h3> <p>While Ruby often uses very limited punctuation and usually prefers English keywords, some punctuation is used to decorate Ruby. Ruby needs no variable declarations. It uses simple naming conventions to denote the scope of variables.</p> <ul> <li><code class="language-plaintext highlighter-rouge">var</code> could be a local variable.</li> <li><code class="language-plaintext highlighter-rouge">@var</code> is an instance variable.</li> <li><code class="language-plaintext highlighter-rouge">$var</code> is a global variable.</li> </ul> <p>These sigils enhance readability by allowing the programmer to easily identify the roles of each variable. It also becomes unnecessary to use a tiresome <code class="language-plaintext highlighter-rouge">self.</code> prepended to every instance member.</p> <h3>Beyond the Basics</h3> <p>Ruby has a wealth of other features, among which are the following:</p> <ul> <li> <p>Ruby has exception handling features, like Java or Python, to make it easy to handle errors.</p> </li> <li> <p>Ruby features a true mark-and-sweep garbage collector for all Ruby objects. No need to maintain reference counts in extension libraries. As Matz says, “This is better for your health.”</p> </li> <li> <p>Writing C extensions in Ruby is easier than in Perl or Python, with a very elegant API for calling Ruby from C. This includes calls for embedding Ruby in software, for use as a scripting language. A SWIG interface is also available.</p> </li> <li> <p>Ruby can load extension libraries dynamically if an OS allows.</p> </li> <li> <p>Ruby features OS independent threading. Thus, for all platforms on which Ruby runs, you also have multithreading, regardless of if the OS supports it or not, even on MS-DOS!</p> </li> <li> <p>Ruby is highly portable: it is developed mostly on GNU/Linux, but works on many types of UNIX, macOS, Windows, DOS, BeOS, OS/2, etc.</p> </li> </ul> <h3>Other Implementations of Ruby</h3> <p>Ruby, as a language, has a few different implementations. This page has been discussing the reference implementation, in the community often referred to as <strong>MRI</strong> (“Matz’s Ruby Interpreter”) or <strong>CRuby</strong> (since it is written in C), but there are also others. They are often useful in certain situations, provide extra integration to other languages or environments, or have special features that MRI doesn’t.</p> <p>Here’s a list:</p> <ul> <li><a href="http://jruby.org">JRuby</a> is Ruby atop the JVM (Java Virtual Machine), utilizing the JVM’s optimizing JIT compilers, garbage collectors, concurrent threads, tool ecosystem, and vast collection of libraries.</li> <li><a href="http://rubini.us">Rubinius</a> is ‘Ruby written in Ruby’. Built on top of LLVM, Rubinius sports a nifty virtual machine that other languages are being built on top of, too.</li> <li><a href="https://github.com/oracle/truffleruby">TruffleRuby</a> is a high performance Ruby implementation on top of GraalVM.</li> <li><a href="http://www.mruby.org/">mruby</a> is a lightweight implementation of the Ruby language that can be linked and embedded within an application. Its development is led by Ruby’s creator Yukihiro “Matz” Matsumoto.</li> <li><a href="http://www.ironruby.net">IronRuby</a> is an implementation “tightly integrated with the .NET Framework”.</li> <li><a href="http://maglev.github.io">MagLev</a> is “a fast, stable, Ruby implementation with integrated object persistence and distributed shared cache”.</li> <li><a href="https://github.com/parrot/cardinal">Cardinal</a> is a “Ruby compiler for <a href="http://parrot.org">Parrot</a> Virtual Machine” (Perl 6).</li> </ul> <p>For a more complete list, see <a href="https://github.com/planetruby/awesome-rubies">Awesome Rubies</a>.</p> <h3>References</h3> <p id="fn1"><sup>1</sup> Matz, speaking on the Ruby-Talk mailing list, <a href="https://blade.ruby-lang.org/ruby-talk/2773">May 12th, 2000</a>.</p> <p id="fn2"><sup>2</sup> Matz, in <a href="http://www.linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html">An Interview with the Creator of Ruby</a>, Nov. 29th, 2001.</p> <p id="fn3"><sup>3</sup> Matz, in <a href="http://www.artima.com/intv/closures2.html">Blocks and Closures in Ruby</a>, December 22nd, 2003.</p> </div> </div> <hr class="hidden-modern" /> <div id="sidebar-wrapper"> <div id="sidebar"> <div class="navigation"> <h3><strong>Get Started</strong>, it's easy!</h3> <ul class="menu"> <li><a href="https://try.ruby-lang.org/">Try Ruby! (in your browser)</a></li> <li><a href="/en/documentation/quickstart/">Ruby in Twenty Minutes</a></li> <li><a href="/en/documentation/ruby-from-other-languages/">Ruby from Other Languages</a></li> </ul> </div> <div class="navigation"> <h3><strong>Explore</strong> a new world…</h3> <ul class="menu"> <li><a href="/en/documentation/">Documentation</a></li> <li><a href="https://rubybib.org/">Academic Research</a></li> <li><a href="/en/libraries/">Libraries</a></li> <li><a href="/en/documentation/success-stories/">Success Stories</a></li> </ul> </div> <div class="navigation"> <h3><strong>Participate</strong> in a friendly and growing community.</h3> <ul> <li><a href="/en/community/mailing-lists/">Mailing Lists</a>: Talk about Ruby with programmers from all around the world.</li> <li><a href="/en/community/user-groups/">User Groups</a>: Get in contact with Rubyists in your area.</li> <li><a href="/en/community/weblogs/">Blogs and Newsletters</a>: Read about what’s happening right now in the Ruby community.</li> <li><a href="/en/community/ruby-core/">Ruby Core</a>: Help polish the rough edges of the latest Ruby.</li> <li><a href="https://bugs.ruby-lang.org/">Issue Tracking</a>: Report or help solve issues in Ruby.</li> </ul> </div> <h3>Syndicate</h3> <p><a href="/en/feeds/news.rss">Recent News (RSS)</a></p> </div> </div> <hr class="hidden-modern" /> </div> </div> </div> <div class="container"> <div id="footer"> <div class="site-links"> <a href="/en/" class="home">Home</a> <a href="/en/downloads/">Downloads</a> <a href="/en/documentation/">Documentation</a> <a href="/en/libraries/">Libraries</a> <a href="/en/community/">Community</a> <a href="/en/news/">News</a> <a href="/en/security/">Security</a> <a href="/en/about/">About Ruby</a> </div> <p> This site in other languages: <a href="/bg/">Български</a>, <a href="/de/">Deutsch</a>, <a href="/en/">English</a>, <a href="/es/">Español</a>, <a href="/fr/">Français</a>, <a href="/id/">Bahasa Indonesia</a>, <a href="/it/">Italiano</a>, <a href="/ja/">日本語</a>, <a href="/ko/">한국어</a>, <a href="/pl/">polski</a>, <a href="/pt/">Português</a>, <a href="/ru/">Русский</a>, <a href="/tr/">Türkçe</a>, <a href="/vi/">Tiếng Việt</a>, <a href="/zh_cn/">简体中文</a>, <a href="/zh_tw/">繁體中文</a>. </p> <p><a href="/en/about/website/">This website</a> is proudly maintained by members of the Ruby community.</p> </div> </div> </body> </html>