Examples from my Ruby book now online

| 4 Comments

All the example code from my Ruby book is now available for download.

As I've mentioned before, you can also browse the book's table of contents.

4 Comments

I haven't seen you mention it, but the book has been available on safari.oreilly.com for a few days now.

The 5.1 example does not run in 1.8.6, even when I require 'enumerator'

>ruby maptest.rb
maptest.rb:21:in `interleave': uninitialized constant StopIteration (NameError)
from maptest.rb:38
123456abcde>Exit code: 1

>ruby maptest.rb
maptest.rb:32:in `bundle': undefined method `next' for # (NoMethodError)
from maptest.rb:32:in `map'
from maptest.rb:32:in `bundle'
from maptest.rb:32:in `loop'
from maptest.rb:32:in `bundle'
from maptest.rb:39
>Exit code: 1

OK. The example is ruby 1.9 specific. Was there something in the preface that told me I should be using ruby 1.9?

Michael,

I'm guessing that you're trying these examples out before you buy the book, right?

Example 5-1 appears in section 5.3.5 of the book. That section is titled "External Iterators" and it begins like this: "Our discussion of enumerators has focused on their use as Enumerable proxy objects. In Ruby 1.9, however, enumerators have another very important use: they are external iterators."

So I think it is clear from the context that this example is not expected to work in Ruby 1.8. The book covers both 1.8 and 1.9. It does not segregate 1.9 features into a separate chapter, but I think I'm always pretty clear about what is a new feature of 1.9 and what is an existing feature of 1.8.

David

Books

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

The classic Java quick-reference

Advertising

Pages

Hosted By

Powered by Movable Type 4.21-en