Essays
Essays
People ask me why I program in Ruby. Is it the clean syntax? the dynamism of objects? the low ratio of code
lines to task accomplished?
And let's be clear about this: I do more than program in Ruby. I resigned from a tenured university professorship
to pursue a life of Ruby programming, writing, and teaching. My professional life revolves around Ruby, and in
an extended sense so does much of my personal life. This isn't a hobby or sideline. This is some serious stuff.
So when people ask me why I program in Ruby, I try to provide the most rigorous, robust, technically precise
explanation I can. What I tell them is: love.
I fell in love with Ruby in early November of 2000, when the first edition of Programming Ruby by Hunt and
Thomas (the Pickaxe book) had just come out. I spotted a copy of the book on the shelf of my local Borders
bookstore. I squinted at the book's spine and thought, Hmmm. I've always been a bit of a language collector,
so I was intrigued. I pulled the book off the shelf and opened it--and here I am, more than ten years later, still in
love.
Love doesn't sound very technical. But technical or not, it's accurate. Moreover, it's why everyone who uses
Ruby uses Ruby. I've never seen anyone convince anyone to use Ruby through rhetoric or argumentation. The
language does all the courting.
That's not to say we don't have Ruby advocacy. Of course we do, and I'm heavily involved in it. But no one
chooses a general-purpose programming language because of a check-list of features or a chart of comparisons
with other languages. Ruby advocacy means creating opportunities for people to see Ruby up close, and creating
conditions favorable to further love affairs.
I hope the ACM Ruby Learning Path will provide you with some walks through the park, late-night chats on the
front porch, and other moments where love between you and Ruby may take hold and flourish.
February 24, 1993: the birthdate of Ruby, according to its creator Yukihiro Matz Matsumoto. Matz
comes to describe Ruby as optimized for programmer pleasure.
1993-2000: Ruby gains great popularity in Japan. Numerous books about Ruby are published. Ruby is
still relatively unknown outside of Japan, but is being discovered by a few keen practitioners.
October 2000: the first edition of Programming Ruby (called the Pickaxe book or the pickaxe, after
its cover illustration) appears. Written by Dave Thomas and Andy Hunt, and published by AddisonWesley, the Pickaxe introduces Ruby to a significant programmer population outside of Japan.
October 2001: the first International Ruby Conference (RubyConf) is held in Tampa, Florida.
Attendees include Matz, Dave Thomas, Andy Hunt, Jim Weirich, Nathaniel Talbott, and about thirty
other Rubyists, many of whom were to become well-known practitioners, authors, and teachers in the
Ruby world.
2001: Jan Arne Petersen releases the first version of JRuby, a Ruby interpreter written on the Java VM.
JRuby would eventually be taken up by Sun and later by Engine Yard, and spearheaded by Charles
Nutter and Thomas Enebo.
November 2002: the second International Ruby Conference. Masayoshi Takahashi, a prominent
Japanese Rubyist (for whom the Takahashi Method of slideset presentation is named) brings with him
from Japan one copy of each Ruby book published there. Laid out on a table, there are twenty-two
books. There are still only a handful of non-Japanese Ruby books in print.
Summer, 2004: Danish programmer David Heinemeier Hansson releases his Ruby on Rails Web
development framework, extracted from the Basecamp project of the company 37 Signals. David
presents Rails at RubyConf 2004, and interest soars.
Fall 2005: attendance at RubyConf triples between 2004 and 2005, due largely to the huge wave of Ruby
interest generated by Rails.
2006: Evan Phoenix begins work on Rubinius, a Ruby interpreter based on the principle of writing as
much of Ruby in Ruby as possible.
December 25, 2007: Ruby 1.9.0 released, incorporating the YARV (Yet Another Ruby VM) bytecode
generator by Koichi Sasada.
2010: Conferences, books, user groups, open-source projects, interpreters -- the Ruby world continues to
thrive and to grow.
RailsConf
EuRuKo, the European Ruby Conference (since 2004)
GoRuCo, the Gotham (New York City) Ruby Conferences
Lone Star Ruby Conference
Mountain West Ruby Conferences
Scottish Ruby Conference (previously Scotland on Rails)
RubyConf Brazil
Ruby Kaigi (Japan)
The Ruby Hoedown
Ruby East
# NoMethodError
The ability for objects to diverge from their birth class constraints also applies to class objects. For example,
the Regexp class (but not the Array class, nor Fixnum, String, etc.) has an escape method:
Regexp.escape("abc.?")
# abc\.\?
Singleton methods on class objects, like Regexp.escape, are one way that Ruby implements class methods,
very roughly the equivalent of static methods in C-like languages.
Ruby has a full toolkit for object individuation (divergence from the API of the object's original class), including
the ability for individual objects to be extended from one or more modules, and a class-based interface to each
object's singleton class, which contains method definitions for the object's singleton methods. The presence of
classes, combined with the full complement of per-object behavior tools, makes Ruby a particularly supple and
dynamic member of the object-oriented language family.
Text processing. Ruby has a strong toolkit for pattern-matching, string scanning, replacement, data
serialization, and text manipulation of many kinds.
Administrative scripting. Ruby's iterative structures are ideal for repetitive and/or slightly divergent
tasks. Also, the language integrates a procedural style into its object-oriented architecture; if you want to
write a quick-and-dirty script to rename a group of files, you can do so easily, or you can work up
something more structured for better maintainability and easier reuse.
Code generation. One of the first English-language books focused on Ruby was Code Generation in
Action by Jack Herrington (Manning Publications, 2003), which used Ruby for its examples.
Prototyping. Without any reduction in respect for Ruby as a production-code language, it's also true that
Ruby makes it relatively easy and pleasurable to prototype complex programs that are destined to be
written for production in other languages. By dispensing with variable typing and initialization, Ruby
lets you focus on implementing logic right from the start (and you may end up using your prototype in
production anyway!).
API wrappers. With its straightforward C API--not to mention the Java connectivity of JRuby--Ruby
makes life easy for those wanting to wrap existing libraries in a higher-level language.
Heavy number crunching. Ruby has a full math library, of course; but if you're looking for the next
prime number, you'll probably want something a bit lower-level.
Optimizations at the cycle-shaving level. Ruby's performance has often been described, quite rightly, as
good enough. Strides are being made, in JRuby and other interpreters as well as the original
interpreter, toward greater performance. But Ruby's thorough dynamism comes at an irreducible price;
it's never going to compete with, say, C at the cycle-shaving level.
Once you start using Ruby, you'll find yourself reaching for it more and more often--and for every time you
decide to use a different language for a project, you may well choose Ruby for several others!
MRI (Matz's Ruby Interpreter -- the original Ruby, feature byte-code compilation based on Koichi
Sasada's YARV VM since version 1.9)
JRuby (Ruby on the JVM)
Rubinius (an innovative approach to Ruby using a relatively small C++ kernel plus much of Ruby
written in Ruby)
IronRuby (Ruby for the .NET platform)
Ruby Enterprise Edition (a performance-tuned Ruby based on the MRI codebase)
MacRuby (an implementation of Ruby 1.9 directly on top of Mac OS X core technologies including
the Objective-C garbage collector)
The proliferation of interpreters came about at a time (roughly 2007 onward) where Ruby was moving from
version 1.8 to 1.9, with a possible 2.0 on the horizon and the status of 1.9 not always entirely clear.1 The question
arose more and more urgently: what exactly is Ruby? Are we dealing with a Lisp-like situation, with many
dialects rather than one standard? What does an interpreter have to do to be considered a Ruby interpreter?
The most important answer to this question came in the form of RubySpec, described on its webpage as an
executable specification for the Ruby programming language using RSpec syntax.2 Here's a sample of
RubySpec, part of the specification of Ruby's behavior with regard to parenthetical capture groups in regular
expressions:
describe "Regexps with grouping" do
it 'support ()' do
/(a)/.match("a").to_a.should == ["a", "a"]
end
it "allow groups to be nested" do
md = /(hay(st)a)ck/.match('haystack')
md.to_a.should == ['haystack','haysta', 'st']
end
# ...
end
RubySpec has gone a long way toward clarifying what a Ruby interpreter should do. At the same time, work is
underway to make Ruby an ISO standard. Hopefully the standard and the test suites will operate in sync, and
continue to make it clear what makes a Ruby a Ruby.
1 Ruby's versioning scheme, through 1.8, had been that odd-numbered minor releases (e.g., 1.7) were development or
experimental releases; even-numbered releases were production releases. This pattern was broken with 1.9, which was a
production release--though 1.9.0 had some instabilities that made it not feel that way. The result was a certain amount of
confusion about numbers and versions, though things stabilized again inside the 1.9 release series.
2 https://github.com/rubyspec/rubyspec. For RSpec, see https://github.com/rspec/rspec/wiki/.
ACM Learning Center -- Ruby Learning Path
Copyright 2011, Ruby Power and Light, LLC
If you abide by these rules, you may find yourself in disagreement with some Ruby practitioners but you'll find
generally that your code blends in nicely to the landscape.
And of course you'll find that even the authors of style guides don't always agree! But you'll get some good
pointers from these guides and the links contained in them:
http://www.caliban.org/ruby/rubyguide.shtml
https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE
http://www.rubyinside.com/ruby-style-guides-and-tools-how-to-write-good-looking-ruby-1272.html