Tải bản đầy đủ (.pdf) (519 trang)

Manning the well grounded rubyist may 2009 ISBN 1933988657 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.14 MB, 519 trang )

Covers Ruby 1.9.1

David A. Black

MANNING


The Well-Grounded Rubyist

Licensed to sam kaplan <>


Licensed to sam kaplan <>


The Well-Grounded
Rubyist
DAVID A. BLACK

MANNING
Greenwich
(74° w. long.)

Licensed to sam kaplan <>


For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.


Sound View Court 3B Fax: (609) 877-8256
Greenwick, CT 06830 email:

©2009 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.

Manning Publications Co.
Sound View Court 3B
Greenwich, CT 06830

Development editor:
Copyeditor:
Typesetter:
Cover designer:

Nermina Miller

Tiffany Taylor
Dottie Marsico
Leslie Haimes

ISBN 978-1-933988-65-8
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 14 13 12 11 10 09

Licensed to sam kaplan <>


For Barbara Aronstein Black,
and in memory of Charles L. Black, Jr. (1915-2001),
with love.
Thanks for the writing genes.

Licensed to sam kaplan <>


Licensed to sam kaplan <>


brief contents
PART 1 RUBY FOUNDATIONS .................................................... 1

PART 2

1




Bootstrapping your Ruby literacy

3

2



Objects, methods, and local variables

3



Organizing objects with classes

4



Modules and program organization

5



The default object (self), scope, and visibility

6




Control-flow techniques

32

60
90
115

148

BUILT-IN CLASSES AND MODULES ............................. 183
7



Built-in essentials

185

8



Strings, symbols, and other scalar objects

9




Collection and container objects

10



Collections central: Enumerable and Enumerator

11



Regular expressions and regexp-based string
operations 319

12



File, I/O, and system operations

213

247

347

vii


Licensed to sam kaplan <>

278


viii

BRIEF CONTENTS

PART 3 RUBY DYNAMICS ....................................................... 373
13



Object individuation

375

14



Callable and runnable objects

15



Callbacks, hooks, and runtime introspection


405

Licensed to sam kaplan <>

441


contents
preface xix
acknowledgments xxi
about this book xxiv
about the cover illustration

xxx

PART 1 RUBY FOUNDATIONS ........................................... 1

1

Bootstrapping your Ruby literacy
1.1

3

Basic Ruby language literacy

4

Meet Interactive Ruby (irb), your new best friend 5 A Ruby

syntax survival kit 5 The variety of Ruby identifiers 6
Method calls, messages, and Ruby objects 8 Writing and
saving a sample program 10 Feeding the program to Ruby 11
Keyboard and file I/O 12








1.2

Anatomy of the Ruby installation 14
The Ruby standard library subdirectory
(Config::CONFIG["rubylibdir"]) 15 The C extensions
directory (Config::CONFIG["archdir"]) 16 The site_ruby
(Config::CONFIG[“sitedir”]) and vendor_ruby
(Config::CONFIG["vendordir"]) directories 16 The gems
directory 17






ix

Licensed to sam kaplan <>



x

CONTENTS

1.3

Ruby extensions and programming libraries

17

Loading external files and extensions 17 “Load”-ing a file in the
default load path 18 “Require”-ing a feature 19




1.4

Out-of-the-box Ruby tools and applications

20

Interpreter command-line switches 21 A closer look at interactive
Ruby interpretation with irb 24 ri and RDoc 26 The rake
task-management utility 28 Installing packages with the gem
command 29









1.5

2

Summary

31

Objects, methods, and local variables
2.1

Talking to objects

32

33

Ruby and object orientation 33 Creating a generic object
Methods that take arguments 36 The return value of a
method 37


34




2.2

Crafting an object: the behavior of a ticket 38
The ticket object, behavior-first 38 Querying the ticket object 39
Shortening the ticket code via string interpolation 40 Ticket
availability: expressing boolean state in a method 41




2.3

The innate behaviors of an object

42

Identifying objects uniquely with the object_id method 43
Querying an object’s abilities with the respond_to? method 44
Sending messages to objects with the send method 45

2.4

A close look at method arguments

46

Required and optional arguments 47 Default values for
arguments 48 Order of parameters and arguments 48





2.5
2.6

What you can’t do in argument lists 51
Local variables and variable assignment 52
Variables, objects, and references 53 References in variable
assignment and reassignment 55 References and method
arguments 56 Local variables and the things that look like
them 57






2.7

3

Summary

58

Organizing objects with classes
3.1


Classes and instances
Instance methods
classes 63

62

60

61


Overriding methods

62

Licensed to sam kaplan <>



Reopening


xi

CONTENTS

3.2

Instance variables and object state
Initializing an object with state


3.3

Setter methods

65

66

68

The equal sign (=) in method names 68 Syntactic sugar for
assignment-like methods 70 Setter methods unleashed 70




3.4

Attributes and the attr_* method family
Automating the creation of attributes
methods 75

3.5

73



72


Summary of attr_*

Inheritance and the Ruby class hierarchy

75

Single inheritance: one to a customer 77 Object ancestry and the
not-so-missing link: the Object class 77 El Viejo's older brother:
BasicObject 78




3.6

Classes as objects and message receivers

79

Creating class objects 79 How class objects call methods 80
A singleton method by any other name… 81 When, and why, to
write a class method 82 Class methods vs. instance methods 84






3.7


Constants up close
Basic use of constants
constants 86

3.8
3.9

4

85
85



Reassigning vs. modifying

Nature vs. nurture in Ruby objects
Summary 89

Modules and program organization
4.1

87

90

Basics of module creation and use

91


A module encapsulating “stack-like-ness” 92 Mixing a module
into a class 94 Leveraging the module further 96




4.2

Modules, classes, and method lookup 98
Illustrating the basics of method lookup 98 The rules of method
lookup summarized 101 Defining the same method more than
once 101 Going up the method search path with super 104






4.3

The method_missing method 105
Combining method_missing and super

4.4

Class/module design and naming
Mix-ins and/or inheritance
classes 112


4.5

Summary

111



106

110

Nesting modules and

113

Licensed to sam kaplan <>


xii

CONTENTS

5

The default object (self), scope, and visibility
5.1

115


Understanding self, the current/default object 116
Who gets to be self, and where 117 Self inside class, module, and
method definitions 119 Self as the default receiver of
messages 122 Resolving instance variables through self 124






5.2

Determining scope 126
Global scope and global variables 126 Local scope 128
The interaction between local scope and self 131 Scope and
resolution of constants 132 Class variable syntax, scope, and
visibility 134






5.3

Deploying method-access rules
Private methods

5.4


140

Writing and using top-level methods
Defining a top-level method
methods 146

5.5

6

Summary

145



143

144

Predefined (built-in) top-level

146

Control-flow techniques
6.1

140

Protected methods




148

Conditional code execution

149

The if keyword and friends 149 Assignment syntax in condition
bodies and tests 153 Case statements 155




6.2

Repeating actions with loops

159

Unconditional looping with the loop method 159 Conditional
looping with the while and until keywords 160 Looping based on
a list of values 163




6.3


Iterators and code blocks

163

The ingredients of iteration 163 Iteration, home-style 164
The anatomy of a method call 164 Curly braces vs. do/end in
code block syntax 165 Implementing times 166 The
importance of being each 168 From each to map 170 Block
parameter and variable semantics 171










6.4



Error handling and exceptions

174

Raising and rescuing exceptions 174 The rescue keyword to the
rescue! 175 Raising exceptions explicitly 177 Capturing an
exception in a rescue clause 178 The ensure clause 180

Creating your own exception classes 181








6.5

Summary

182

Licensed to sam kaplan <>


xiii

CONTENTS

PART 2 BUILT-IN CLASSES AND MODULES...................... 183

7

Built-in essentials
7.1
7.2


185

Ruby’s literal constructors 186
Recurrent syntactic sugar 187
Defining operators by defining methods
operators 190

7.3

188



Customizing unary

Bang (!) methods and “danger” 190
Destructive (receiver-changing) effects as danger 191
Destructiveness and “danger” vary independently 192

7.4

Built-in and custom to_* (conversion) methods

193

String conversion: to_s 194 Array conversion with to_a and the
* operator 197 Numerical conversion with to_i and to_f 198
The role-playing to_* methods 199





7.5

Boolean states, boolean objects, and nil 201
True and false as states 201
The special object nil 205

7.6

Comparing two objects
Equality tests 206
module 206

7.7





true and false as objects

203

206

Comparisons and the Comparable

Inspecting object capabilities


208

Listing an object’s methods 209 Querying class and module
objects 210 Filtered and selected method lists 210




7.8

8

Summary

211

Strings, symbols, and other scalar objects
8.1

Working with strings

213

214

String notation 214 Basic string manipulation 218
Querying strings 222 String comparison and ordering 224
String transformation 225 String conversions 228 String
encoding: a brief introduction 229







8.2

Symbols and their uses



231

The chief characteristics of symbols 232 Symbols and
identifiers 233 Symbols in practice 234 Strings and symbols
in comparison 236






Licensed to sam kaplan <>


xiv

CONTENTS

8.3

8.4

Numerical objects

237

Numerical classes

238

Times and dates

240



Performing arithmetic operations

238

Instantiating date/time objects 240 Date/time query
methods 242 Date/time formatting methods 243
Date/time conversion methods 244




8.5

9


Summary

246

Collection and container objects
9.1
9.2

247

Arrays and hashes in comparison 248
Collection handling with arrays 249
Creating a new array 250 Inserting, retrieving, and removing
array elements 253 Combining arrays with other arrays 255
Array transformations 257 Array querying 258






9.3

Hashes

258

Creating a new hash 259 Inserting, retrieving, and removing
hash pairs 260 Specifying default hash values and

behavior 261 Combining hashes with other hashes 262
Hash transformations 263 Hash querying 264 Hashes as
method arguments 265








9.4

Ranges

266

Creating a range

9.5



Range-inclusion logic

268

Set creation 270 Manipulating set elements
and supersets 274


271

Sets

267



270


9.6

Exploring the set.rb source code
Set#initialize 274
Set#add? 276

9.7

10

Summary



Set#include?



Subsets


274
276



Set#add and

277

Collections central: Enumerable and Enumerator 278
10.1
10.2
10.3

Gaining enumerability through each 279
Enumerable boolean queries 281
Enumerable searching and selecting 283
Getting the first match with find 284 Getting all matches with
find_all (a.k.a. select) and reject 285 Selecting on “threequal”
matches with grep 286 Organizing selection results with
group_by and partition 287






Licensed to sam kaplan <>



xv

CONTENTS

10.4

Element-wise enumerable operations

288

The first method 288 The take and drop methods
The min and max methods 291


10.5

The relatives of each

290

292

The each_with_index method 292 The each_slice and each_cons
methods 293 The cycle method 294 Enumerable reduction
with inject 294





10.6



The map method

296

The return value of map
map! 297

10.7
10.8

296

Strings as quasi-enumerables
Sorting enumerables 299



In-place mapping with

298

Where the Comparable module fits into enumerable sorting (or
doesn’t) 301 Defining sort-order logic with a block 301
Concise sorting with sort_by 302



10.9

Enumerators and the next dimension of
enumerability 302
Creating enumerators with a code block 303 Attaching
enumerators to other objects 306 Implicit creation of enumerators
by blockless iterator calls 307




10.10

Enumerator semantics and uses

307

How to use an enumerator’s each 308 Protecting objects with
enumerators 309 Fine-grained iteration with enumerators 311
Adding enumerability with an enumerator 311




10.11

Enumerator method chaining 313
Economizing on intermediate objects 313 Indexing enumerables
with with_index 315 Exclusive-or operations on strings with
enumerators 316





10.12

11

Summary

318

Regular expressions and regexp-based string operations
11.1
11.2

What are regular expressions? 320
Writing regular expressions 321
Seeing patterns 321
expressions 321

11.3



Simple matching with literal regular

Building a pattern in a regular expression

323


Literal characters in patterns 323 The wildcard character .
(dot) 323 Character classes 324




Licensed to sam kaplan <>

319


xvi

CONTENTS

11.4

Matching, substring captures, and MatchData

325

Capturing submatches with parentheses 325 Match success and
failure 327 Two ways of getting the captures 328 Other
MatchData information 329




11.5




Fine-tuning regular expressions with quantifiers, anchors,
and modifiers 330
Constraining matches with quantifiers 330 Greedy (and nongreedy) quantifiers 332 Regular expression anchors and
assertions 335 Modifiers 337






11.6

Converting strings and regular expressions
to each other 338
String to regexp idioms
string 340

11.7

12



Going from a regular expression to a

Common methods that use regular expressions
String#scan

gsub! 344

11.8

338

Summary

341 String#split 343 sub/sub! and gsub/
Case equality and grep 345






346

File, I/O, and system operations
12.1

341

347

How Ruby’s I/O system is put together 348
The IO class 348 IO objects as enumerables 349 STDIN,
STDOUT, STDERR 350 A little more about keyboard
input 351







12.2

Basic file operations

352

The basics of reading from files 352 Line-based file
reading 353 Byte- and character-based file reading 354
Seeking and querying file position 354 Reading files with File
class methods 355 Writing to files 356 Using blocks to scope
file operations 357 File enumerability 358 File I/O
exceptions and errors 359












12.3




Querying IO and File objects

360

Getting information from the File class and the FileTest module
Deriving file information with File::Stat 362

12.4

Directory manipulation with the Dir class
Reading a directory’s entries
querying 365

12.5

Summary



362

Directory manipulation and

File tools from the standard library
The FileUtils module 366
The StringIO class 370


12.6

363



360

366

The Pathname class

372

Licensed to sam kaplan <>

368


xvii

CONTENTS

PART 3 RUBY DYNAMICS .............................................. 373

13

Object individuation
13.1


375

Where the singleton methods are: the singleton class

376

Dual determination through singleton classes 377
Examining
and modifying a singleton class directly 377 Singleton classes on
the method-lookup path 380 Class methods in (even more)
depth 384






13.2

Modifying Ruby’s core classes and modules
The risks of changing core functionality 386
changes 391 Pass-through overrides 393
with extend 396





13.3


BasicObject as ancestor and class
Using BasicObject
BasicObject 401

13.4

14

Summary

400



Additive
Per-object changes

399

Implementing a subclass of

404

Callable and runnable objects
14.1



386


405

Basic anonymous functions: the Proc class

406

Proc objects 407 Procs and blocks, and how they differ 407
Block-Proc conversions 409 Using Symbol#to_proc for
conciseness 411 Procs as closures 413 Proc parameters and
arguments 415






14.2
14.3

Creating functions with lambda and ->
Methods as objects 417
Capturing Method objects
objects 418

14.4



418


The eval family of methods



416

The rationale for methods as

420

Executing arbitrary strings as code with eval 420 The dangers of
eval 421 The instance_eval method 422 The most useful
eval: class_eval (a.k.a. module_eval) 423




14.5



Parallel execution with threads

425

Killing, stopping, and starting threads 426 A threaded date
server 428 Writing a chat server using sockets and threads 429
Threads and variables 431 Manipulating thread keys 432







14.6

Issuing system commands from inside Ruby
programs 435
The system method and backticks 435
programs via open and popen3 437

14.7

Summary



Communicating with

440

Licensed to sam kaplan <>


xviii

CONTENTS

15


Callbacks, hooks, and runtime introspection
15.1

Callbacks and hooks

441

442

Intercepting unrecognized messages with method_missing 442
Trapping include operations with Module#included 445
Intercepting extend 446 Intercepting inheritance with
Class#inherited 448 The Module#const_missing method 449
The method_added and singleton_method_added methods 450




15.2

Interpreting object capability queries

452

Listing an object’s non-private methods 452 Listing private and
protected methods 454 Getting class and module instance
methods 455 Listing objects’ singleton methods 457







15.3

Introspection of variables and constants
Listing local, global, and instance variables

15.4

Tracing execution

460



Writing a tool for

Callbacks and method inspection in practice
The MicroTest background: MiniTest
implementing MicroTest 467

15.6

459

460

Examining the stack trace with caller
parsing stack traces 462


15.5

459

Summary
index

465



464

Specifying and

470

471

Licensed to sam kaplan <>


preface
In 2006, Manning published my book Ruby for Rails: Ruby Techniques for Rails Developers.
My goal in writing Ruby for Rails—or, as it has come to be known, R4R—was to provide
Rails developers with both an understanding of the fact that being a Rails developer
means being a Ruby developer, and a solid grasp of Ruby. I chose Ruby topics for
inclusion (and exclusion) based on my judgment as to their relative importance for
people who wanted to learn Ruby mainly in order to use Rails correctly and effectively.

Critical response to R4R was very good. The book filled a void: it was neither just a
Ruby book nor just a Rails book, but a Ruby book “optimized,” so to speak, for the
Rails developer. I was pleased by the book’s reception—and particularly by the many
people who, after reading it, asked me whether I had any plans to write a whole book
just about Ruby, and encouraged me to write one.
And that, to make a long story short, is what I have done.
The Well-Grounded Rubyist is a “just Ruby” book, and it’s written to be read by anyone interested in Ruby. It’s a descendant of R4R but not exactly an update. It’s more
of a repurposing. There’s some overlap with R4R, but there’s also a lot of new material
(more than I originally anticipated, in fact); and everything, overlap or not, has been
oiled and polished and spiffed up to work with Ruby 1.9.1, the newest version of Ruby
(and very new) at the time the book went to press.
Mind you, I don’t mean for Rails developers not to read The Well-Grounded Rubyist.
On the contrary: I’m optimistic that in the three years since R4R was published, the
idea that Rails developers should learn Ruby has become commonplace, and many

xix

Licensed to sam kaplan <>


xx

PREFACE

people who first got into Ruby through Rails have gotten interested in Ruby in its own
right. I want this book to be there waiting for them—and for the many people who are
discovering Ruby through completely different channels.
So whatever brings you here, I hope you enjoy the book.

Licensed to sam kaplan <>



acknowledgments
Work on this book was, in part, by way of a reunion with many of the people at Manning whom I’d worked with on my last book—and in part a first chance to work with
some Manning staff I hadn’t known before. All of the associations were enjoyable and
productive.
Throughout the project, development editor Nermina Miller kept everything on
track, helping me to strike a balance between acceptance of the fact that the book was
taking longer to do than I thought it would, and the need to not let it take forever.
Her advice on textual flow, clarity, topic emphasis, and many other matters ensured a
high standard of construction, and her help with the practicalities of scheduling and
delivery contributed greatly to the momentum of the project.
I cannot say enough in praise of the individual and combined forces of the production personnel who worked on the book. Production manager Mary Piergies guided
the project smoothly and quickly, navigating with authority and skill past the occasional sandbar that might otherwise have impeded it. Dottie Marsico not only handled
the logistics of the graphics, as she had with Ruby for Rails, but also typeset the entire
book, and masterfully. I was happy to be reunited with copyeditor Tiffany Taylor, to
whom I pay the ongoing tribute of reading her copyedited texts with “Show Insertions
and Deletions” switched off. Her contributions are everywhere in the text. Proofreader Katie Tennant saw to the finishing touches with thoroughness and an expert
eye, retaining her high standards and her patience even when circumstances made it
necessary to apply the finishing touches, as it were, more than once.

xxi

Licensed to sam kaplan <>


xxii

ACKNOWLEDGMENTS


Review editor Karen Tegtmeyer once again lined up impressive arrays of reviewers
for the manuscript-in-progress. Megan Yockey, my first Manning contact and the person responsible for acquiring my first Manning manuscript, was available as always to
field questions and facilitate contact within the organization. I’m also grateful to Manning webmaster Gabriel Dobrescu for maintaining the Author Forum and other
online information. Cover designer Leslie Haimes helped me settle on a picture that
pleases me very much and suits the book nicely.
I was fortunate enough to have as my technical editor Gregory Brown, one of the
most creative thinkers and rigorous technicians I know in the Ruby world. His comments enhanced many a passage in the book and steered me away from making at
least a generous handful of out-and-out mistakes.
The timeline of The Well-Grounded Rubyist encompassed the tenures of two marketing directors at Manning, Ron Tomich and Steven Hong, both of whom I have
enjoyed working with. I look forward to working further with Steven in the coming
months and feel in very capable hands when it comes to publicity.
I worked closely with Associate Publisher Michael Stephens, who was consistently
available, responsive, and helpful both along the straight-aways and at the occasional
hurdle. The belief shown in my projects by Manning Publisher Marjan Bace has given
me the confidence to explore structures and topics in the knowledge that I have both
a supporter and an exacting critic on my side. I’m particularly grateful to Marjan and
Mike for their receptiveness to the book’s rather offbeat, but I believe expressive, title.
It’s my great pleasure to spend my time surrounded—electronically or otherwise—
by literally hundreds of friends and colleagues in the Ruby world, from whom I learn
constantly and with many of whom I feel I have moved through Ruby history as one
moves with one’s classmates through school. I’m protected from having even to try to
name all of them by their sheer numbers; but rather than chicken out entirely, I will
say that I owe particular thanks with respect to my own absorption of the development
of Ruby between versions 1.8 and 1.9 to Gregory Brown, Brian Candler, the late Guy
Decoux, Rick DeNatale, Ryan Davis, Martin Duerst, Thomas Enebo, David Flanagan,
Chad Fowler, James Edward Gray II, Erik Kastner, Shugo Maeda, Yukihiro Matsumoto,
Nobuyoshi Nakada, Jeremy McAnally, Charles Nutter, Evan Phoenix, Koichi Sasada,
Josh Susser, Dave Thomas, and Jim Weirich. I am also grateful to the denizens of the
#caboose and #ruby-talk IRC channels, as well as those of the ruby-talk and ruby-core
mailing lists, for tremendous amounts of discussion, explanation, exploration, and

just plain Ruby fun.
Thanks also to all who reviewed the manuscript in progress: Fabio Angius, Ed
Borasky, Daniel Bretoi, Rick DeNatale, Robert Dempsey, Pat Dennis, Greg Donalds,
Mark Eagle, John Griffin, Philip Hallstrom, Bob Hutchinson, Francis Hwang, Robert
Klemme, Albert Koscielny, Ryan Lowe, Pete McBreen, Curtis Miller, Patrick Steger,
Mike Stok, Deepak Vohra, Doug Warren, and Austin Zeigler. Their feedback was both
substantial and substantive, and I’m glad to have had the chance to improve and correct the book along the lines they suggested. I’m also grateful to those who have
posted corrections and suggestions on the Author Forum on the Manning website.

Licensed to sam kaplan <>


ACKNOWLEDGMENTS

xxiii

To Yukihiro “Matz” Matsumoto, the creator of Ruby, go my perennial and perpetual thanks for creating a technology to which I felt such an attraction that I literally
changed careers so I could participate in it. Matz’s accomplishment impresses me
more and more as the years go by.
Finally, thanks as always to the many friends and family members who, although
not necessarily technically inclined, have given me support, shown interest in my
work, shared my excitement, and helped me through the tough phases. Technical or
not, they’re my inspiration.
And one post-final word: any errors in the book are my responsibility alone.

Licensed to sam kaplan <>


about this book
Welcome

…to The Well-Grounded Rubyist. This book is a reworking of my book Ruby for Rails
(Manning, 2006) and builds on the Ruby language explication present in that book so
that a broader audience of Ruby learners can make use of it and learn from it.
Ruby is a general-purpose, object-oriented, interpreted programming language
designed and written by Yukihiro Matsumoto (known widely as “Matz”). It was introduced in 1994 and became popular in Japan during the 1990s. It’s known and
admired for its expressiveness—its ability to do a lot with relatively little code—and
the elegance and visual smoothness of its syntax and style. Ruby has proven useful and
productive in a wide variety of programming contexts, ranging from administrative
scripting to device embedding, from web development to PDF document processing.
Moreover, and at the risk of sounding non-technical, Ruby programming is fun. It’s
designed that way. As Matz has said, Ruby is optimized for the programmer experience. Indeed, Ruby started as Matz’s pet project and gained attention and traction
because so many other programmers got pleasure from the same kind of language
design that Matz did.
The first English-language book on Ruby (Programming Ruby by Dave Thomas and
Andy Hunt) appeared in late 2000 and ushered in a wave of Ruby enthusiasm outside
of Japan. Ruby’s popularity in the West has grown steadily since the appearance of the
“Pickaxe book” (the nickname of the Thomas-Hunt work, derived from its cover illustration). Four years after the first edition of the Pickaxe, the introduction of the Ruby
on Rails web application development framework by David Heinemeier Hansson

xxiv

Licensed to sam kaplan <>


×