Developers the world over talk about
Programming Ruby and the Ruby language. . .
“Ruby is a wonderf ully powerful and useful language, and whenever I’m working
with it, this book is at my side.”
Martin Fowler, Chief Scientist, Though tWorks
“If your world revolves aroun d Java, as mine did, then you need this outstanding book
to learn all the wonderful things you’re missing. The re’s ju st one catch: you’ll be
spoiled from then on. Indee d, after re ading just a few pages of Programming Ruby,
programming in any language other than Ruby will feel like you’re pushing rope.”
Mike Clark, Author and Consultant
“Ruby is sma rt, elegant, and fun, and it deserves a book that’s smart, elegant, and fun.
The first edition of Programming Ruby was such a book; the second edition is even
better.”
James Britt, Administrato r,
http://ruby-doc.org
“The best reaso n to learn a new programming language is to learn to think differently.
The best way to learn to thin k the Ruby way is to read Programming Ruby . Several
years ago, with the first edition of this book, I did just that. Since then, I’ve had a
constant stream of enjoyable Ruby prog ramming experiences. This is d ue in no
insignificant part to the quality of the source from which I learned the language. I’m
not the only person I’ve heard say that every language sho uld have a book like this.”
Chad Fowler, Codirec tor, Ruby Central, Inc.
“The PickAxe got me started on Ruby. It is still the first book I turn to.”
Ryan Davis, Founde r, Seattle.rb
“This book changed my life. Sounds rather cliché d, but it’s the truth. After six y ears
and 300,000 lines of Java code, I needed a change. That change occurred upon reading
the first edition of this book. With the support of a solid community and ever-growing
foundation of superb libraries, I founded a company that largely profits from applying
Ruby to solve real-world problems. Ruby is ready for prime time, and this new
version of the PickAxe will show a waiting world what a gem Ruby really is.”
Rich Kilmer, President and CEO, InfoE ther LLC
“The first edition of PickAxe has been a desk-side companion for years. The second
edition will be an eagerly awaited replacem ent.”
Tom Enebo, JRuby Developer
“The first edition of Programming Ruby b rought about no less than the introduction of
Ruby on a large scale ou tside of Japan, in the process becoming the de fa cto standard
published language reference and an oft-cited m odel of clear, effective technical
writing. The appearance of the second, expanded edition is exciting for Ruby
programmers around the world and will no doubt attract a fresh wave of newcomers to
this elegant, versatile language.”
David A. Black, Ph.D., Codirector, Ruby Central, Inc.
“Ruby is my de finite choice for all scripting and proto typing issues, an d this book will
help you to discover its usefulness as well as its beauty. Apart from that, it’s really fun
to re ad!”
Robert Klemme
“I bought the first edition of this b ook the day it was released and had a fantastic time
using it to learn Ruby. I eventually bought a second copy to keep at home. But Ruby
has changed since then. I’m delighted that this second edition of Programming Ruby
is available to help a new round of programmers lear n about this fantastic, beautiful
languag e. And it’s not just good news for Ruby newbies, of course—like me, most
Ruby developers will want a copy (no, make that two) so that all of the details about
today’s Ruby will be close at hand.”
Glenn Vanderburg, Software Architect, Countrywide Financial
“Ruby is one of those great languages that takes an afternoon to start using and years
(maybe a lifetime) to master. In C, I’m a lways having to work around the limitations
of the language; in Ruby, I’m always discovering a neater, cleaner, more efficient way
to d o thin gs. Programming Ruby is the essential reference to the Ruby langu age. More
than just teaching you the sy ntax, it teaches you the spirit and the feel of the language.”
Ben Giddings
“Confuciu s said, “What you hear, you forget.” He also said, “What you do you
understand.” But it’s not easy to a ctually “do” things unless you’re using a great
languag e with strength in quick and clean pr ototyping . In my case, this language is
Ruby! Thank you!”
Michael Neumann
Programming Ruby
The Pragm atic Progra mmers’ Guide
Second Editio n
Dave Thomas
with
Chad Fowler
and An dy Hunt
The Pragma tic Bookshelf
Raleigh, North Carolina Dallas, Texas
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC, was aware
of a trademark claim, the designations have been printed in initial capital letters or in all capitals.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility
for errors or omissions or for damages that may result from the use of information (including program
listings) contained herein.
This book is a heavily revised version of the book Programming Ruby, originally published by Addison
Wesley. This book is printed with their permission.
Our Pragmatic courses, workshops, and other products can help you and your team create better software
and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at
http://www.pragmaticprogrammer.com
Copyright
©
2005 The Pragmatic P rogrammers, LLC. All rights reserved. No part of this publication may be
reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical,
photocopying, recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN 0-9745140-5-5
Text printed on acid-free paper.
First Printing, October 2004
Version: 2004-9-30