Professional Documents
Culture Documents
Table of Contents
So you want to learn Ruby... .................................................................................................. 4
2. Ruby Gems........................................................................................................................ 11
3. Resources ......................................................................................................................... 21
ii
Ruby Compendium - Table of Contents
3.2 Books................................................................................................................................................ 22
3.3 Podcasts and Screencasts............................................................................................................... 22
iii
Ruby Compendium - So you want to learn Ruby...
There are many different ways to learn new programming languages. Typically, you’d start reading
tutorials online, try a few example programs, maybe buy a book and start reading it. That’s what most
people do nowadays, and it works, in the end. The downside of this is that you may spend weeks or
even months trying to get the hang of the language, spend a lot of time trying to find information
about it, ask dumb questions in forums and mailing lists, re-invent the wheel only to find out —months
later— that someone already made a library which does exactly the same thing as yours, but in a much
better way.
You can learn through mistakes, but there’s no harm in starting with the right foot.
This Ruby Compendium gives you an overview of the Ruby Ecosystem from 10,000ft. It briefly describes
the language, its libraries, and what resources you can find online. By the time you finish reading
this, you will not know how to write Ruby programs (yet) but you’ll definitely know how to learn this
amazing and powerful language and where to look for information and help.
This book was authored using Glyph and the PDF version was produced with Prince XML.
The Ruby logo is copyright © 2006, Yukihiro Matsumoto, and used under the terms of the Creative
Commons Attribution-ShareAlike 2.5 License.
iv
Ruby Compendium - Quick Tour
▪ 1.8 – The former stable version, which is still widely used in production and it is still updated.
▪ 1.9 – As of release 1.9.2, this is considered the current stable and recommended version of the
language. Although most third-party libraries work with it, some old and now unmaintained
libraries may not. The good news is that there are normally newer and better libraries available
instead.
5
Ruby Compendium - Quick Tour
Different implementations of Ruby offer different degrees of support to one or the other version.
Compared to 1.8, Ruby 1.9 has some additional syntax for certain expressions, improved character
encoding support and a few new bundled libraries and features.
If you’re new to Ruby and you have no particular restrictions or needs, you should start learning Ruby
using version 1.9 (either YARV, JRuby or MacRuby)!
There are many articles and presentations online outlining the changes in Ruby 1.9, for
example:
1.2.1 MRI
Matz’s Ruby Interpreter is the official Ruby 1.8 implementation, written in C by Yukihiru Matsumoto,
the creator of Ruby. As of Ruby 1.9, it has been replaced with YARV.
1.2.2 YARV
Yet Another Ruby VM, the official Ruby 1.9 implementation is a bytecode interpreter written Koichi
Sasada. It has been tested to be faster than MRI.
1.2.3 JRuby
An implementation of the Ruby language running on the Java Virtual Machine, mature and usable
in production. It offers real threading, performance improvements, and Java interoperability. Fully-
compatible with both Ruby 1.8 and 1.9.
6
Ruby Compendium - Quick Tour
1.2.4 Rubinius
A C++ and LLVM-powered Ruby implementation. Although still not as mature as YARV or JRuby, it’s
getting there. It currently aims at being compatible with Ruby 1.8.7, although support for Ruby 1.9 is
planned.
1.2.5 MacRuby
A Mac-only Ruby implementation compatible with Ruby 1.9, specifically tuned for Mac OS X operating
systems.
1.2.6 IronRuby
A .NET implementation of the Ruby Programming Language, compatible with Ruby 1.8.6 (IronRuby
1.0) and 1.9 (IronRuby 1.1.1 onwards). Not as mature as the other implementations.
Being a high-level, interpreted language, Ruby is slower than compiled languages like C
or C++ or even other interpreted languages like Perl 5. However, this may vary depending
on the implementation.
▪ If you are interested in Ruby benchmarks, check out Antonio Cangiano’s Great Ruby
Shootout, which also includes data on Ruby Enterprise Edition and MagLev
implementations.
▪ If you are interested in benchmarks between Ruby implementations and other
languages, the Computer Language Benchmark Game is a good place to start.
1.3 Syntax
Teaching you how to program in Ruby goes beyond the scope of this book, however, this section will
show you at least what Ruby code looks like. If you know another programming language already,
some things may already be familiar to you. If you don't, hopefully the following code will not appear
too intimidating.
7
Ruby Compendium - Quick Tour
8
Ruby Compendium - Quick Tour
Most likely, this is not going to be enough. That’s when the Standard Library comes into play: it’s a
large collection of internal libraries that ships with every Ruby implementations. There are libraries
to connect to the Internet, to read/write to various file formats such as CSV or YAML, to work with
files and paths, access system features, and so on.
Unlike core classes, standard libraries must be required specifically if needed, before they can be used.
On core libraries and the Standard Library, checkout the official documentation:
▪ Core Reference
▪ Standard Library Reference
Overwhelmed? Don’t know where to start? Familiarize yourself with the Enumerable
module; you won’t regret it!
9
Ruby Compendium - Quick Tour
The beauty of this is that you can (and should) combine elements from different paradigms, resulting
in very powerful and expressive code. What I really like about Ruby though is its inherent dynamic
nature.
All these things make the language very flexible and powerful. Do not overuse Ruby’s power: if your
code starts to look like black magic, you’re probably going too far.
…on specific and advanced Ruby features, check out these articles:
10
Ruby Compendium - Ruby Gems
The Rubygems packaging system is now included in most Ruby implementation and distributions.
Installing a gem and all its dependencies is as easy as issuing gem install <name of the gem>. So for
example if you want to install the rails gem, you can just run
…and it will be automatically downloaded and installed on your system, along with the other gems it
depends on.
2.1 RubyGems.org
There are over 1300 different gems publicly (and freely!) available. Luckily, the official gem host site,
RubyGems.org makes it very easy to find what you're looking for: just search for a particular gem or a
functionality you're looking for, and browse through the results. You can also register and push your
own gems for other people to use.
What happened to RubyForge?
If you started to learn Ruby a few years ago, the RubyForge was the place to find user-
created ruby code and gems. The site is still there, but nowadays Rubyists prefer using
GitHub as host for their source code repositories and RubyGems.org as the home for their
gems.
11
Ruby Compendium - Ruby Gems
A site to check when you don’t know much of what has been done in a particular domain is The Ruby
Toolbox, which organizes quite a lot of gems into categories. This section is somewhat similar, but it
focuses on just a few common tasks and a small set of hand-picked gems.
“cmdparse provides classes for parsing commands on the command line; command line options are parsed
using optparse or any other option parser implementation.”
gli
“An application and API for describing command line interfaces that can be used to quickly create a shell
for executing command-line tasks.”
highline
“A high-level IO library that provides validation, type conversion, and more for command-line interfaces.
HighLine also includes a complete menu system that can crank out anything from simple list selection to
complete shells with just minutes of work.”
hirb
“A mini view framework for console/irb that’s easy to use, even while under its influence. Console goodies
include a no-wrap table, auto-pager, tree and menu”
2.2.2 Documentation
glyph
12
Ruby Compendium - Ruby Gems
rdoc
“RDoc produces HTML and online documentation for Ruby projects. RDoc includes the rdoc and ri tools for
generating and displaying online documentation.”
yard
“YARD is a documentation generation tool for the Ruby programming language. It enables the user to
generate consistent, usable documentation that can be exported to a number of formats very easily, and
also supports extending for custom Ruby constructs such as custom class level definitions.”
“Bundler manages an application’s dependencies through its entire life, across many machines,
systematically and repeatably.”
jeweler
bones
“Mr Bones is a handy tool that creates new projects from a code skeleton.”
13
Ruby Compendium - Ruby Gems
▪ Download: http://www.rubygems.org/gems/bones
▪ Documentation: http://www.rubydoc.info/gems/bones
fxruby
wxruby
“wxRuby allows the creation of graphical user interface (GUI) applications via the wxWidgets library.
wxRuby provides native-style GUI windows, dialogs and controls on platforms including Windows, OS X and
Linux.”
qtruby4
rugui
“RuGUI is a framework which aims to help building desktop applications. RuGUI was mostly inspired by the
Ruby on Rails framework, taking most of its features from it.”
14
Ruby Compendium - Ruby Gems
“BlueCloth is a Ruby implementation of Markdown, a text-to-HTML conversion tool for web writers. To
quote from the project page: Markdown allows you to write using an easy-to-read, easy-to-write plain text
format, then convert it to structurally valid XHTML (or HTML).”
github-markup
“This gem is used by GitHub to render any fancy markup such as Markdown, Textile, Org-Mode, etc. Fork it
and add your own!”
haml
“Haml (HTML Abstraction Markup Language) is a layer on top of XHTML or XML that’s designed to express
the structure of XHTML or XML documents in a non-repetitive, elegant, easy way, using indentation rather
than closing tags and allowing Ruby to be embedded with ease. It was originally envisioned as a plugin for
Ruby on Rails, but it can function as a stand-alone templating engine.”
liquid
mustache
15
Ruby Compendium - Ruby Gems
template language. Think of Mustache as a replacement for your views. Instead of views consisting of ERB
or HAML with random helpers and arbitrary logic, your views are broken into two parts: a Ruby class and
an HTML template.”
rdiscount
redcloth
nanoc
“a web publishing system written in Ruby for building small to medium-sized websites.”
toto
16
Ruby Compendium - Ruby Gems
webby
“Webby is a fantastic little website management system. It would be called a content management system
if it were a bigger kid. But, it’s just a runt with a special knack for transforming text. And that’s really all it
does – manages the legwork of turning text into something else, an ASCII Alchemist if you will.”
2.2.7 Testing
bacon
“Bacon is a small RSpec clone weighing less than 350 LoC but nevertheless providing all essential features.”
cucumber
minitest
“minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
minitest/unit is a small and incredibly fast unit testing framework.”
rspec
“RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software
development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven
Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design
aspects of TDD.”
shoulda
17
Ruby Compendium - Ruby Gems
“Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable
productivity. It encourages beautiful code by favoring convention over configuration.”
sinatra
padrino-framework
merb-core
ramaze
18
Ruby Compendium - Ruby Gems
camping
rack
“Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.”
thin
unicorn
“Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-
bandwidth connections and take advantage of features in Unix/Unix-like kernels.”
19
Ruby Compendium - Ruby Gems
nokogiri
“An HTML, XML, SAX, & Reader parser with the ability to search documents via XPath or CSS3 selectors…
and much more”
xml-simple
20
Ruby Compendium - Resources
The following section contains a small set of hand-picked web sites, books and podcasts which you
should definitely have a look at. For even more community resources, check out the Community Page
on the Official Ruby Web Site.
Ruby Koans – Learn Ruby (and testing) through Koans. Probably the coolest way to learn Ruby right
now.
Ruby Learning – Ruby guru Satish Talim’s web site about learning the Ruby language. It contains
tutorials, study notes, and even online classes.
RubyDoc.info – Your one-stop resource for reference documentation. Everything from Ruby core,
Standard Library, gems, and even Github-hosted Ruby projects.
The Ruby Toolbox – A collection of ruby resources and libraries, organized by category and
popularity.
RubyCommitters.org – List of all the Ruby core committers. Created by Aaron Petterson, currently
looking for a fancy CSS makeover.
21
Ruby Compendium - Resources
3.2 Books
The Humble Little Ruby Book – A nicely-written free book on Ruby, by Jeremy McAnally
The Little Book of Ruby – An 87-page free introduction covering Ruby basics.
Programming Ruby – The first edition of the so-called Pickaxe book, available for free, by Dave
Thomas, Chad Fowler and Andy Hunt
Why’s (poignant) guide to Ruby – The legendary book by why the lucky stiff. With foxes, little elves,
and… chunky bacon!). Exquisitely weird and witty.
All the books mentioned so far are free, but there’s plenty of published books on Ruby.
Check out the following titles:
22
Ruby Compendium - Notable Rubyists
23
Ruby Compendium - Notable Rubyists
24