Errata for Ruby for Rails

Note from the author

I've organized the errata on this page into three categories, in descending order of importance to you, the reader:

As always, please report any errors you see to the Author Online Forum for Ruby for Rails. And stop by to talk about the book in general!

Thanks, and enjoy Ruby for Rails

David A. Black


Substantive errors

Pages 203-204:

The built-in top-level methods such as puts and print are, as stated, private instance methods of the Kernel module. However, the ones you write are private instance methods of the Object class, not the Kernel module. The effect is the same either way, with regard to method calling, but there is a distinction in where they're defined.


Page 249, Table 9.4:

The fifth row should read:

"string" "string" true


Page 253:

On line 2, "-1, 1, or 0" should be "-1, 0, or 1".


Page 403:

The statement that, by using explicit SQL rather than Ruby code to gather ActiveRecord objects, you'll end up with special ActiveRecord collections, rather than plain arrays, is inaccurate. In both cases, you'll end up with arrays, including the extended behaviors that Rails adds to all arrays, but not the further extended behaviors of special ActiveRecord collection objects.


Page 430-433:

The discussion of the instrument/_list.rhtml partial, and the instrument/show action, conflates two things that should be separate.

(See the code for the second version of R4RMusic, including a slightly amended list/show action.)


Glitches

Page 9:

"method-call print" should be "method call puts".


Page 47:

The URL for the book's home page should be http://www.manning.com/books/black.


Page 130:

The "discount" method should be:

def discount(percent)
  @price = @price - (@price * percent) / 100
end


Page 183:

"(obj)" should be "(c)"


Page 189:

On the last line of the code snippet at top, this:

c.new.examine_global

should be this:

c.examine_global


Page 218:

The puts statement in the last code sample should read:

puts "#{c}\t#{Temperature.c2f(c)}"


Page 299:

h.each_key {|k| puts "The next key is #{key}." }
h.each_value {|v| puts "The next value is #{value}." }

should be:

h.each_key {|k| puts "The next key is #{k}." }
h.each_value {|v| puts "The next value is #{v}." }


Page 305:

The definition of class Rainbow should include the line:

include Enumerable


Page 348:

In this statement:

When abc is called, the string "Inside new method!" is printed out.

the output of the abc method should actually be given as "Hi!"


Page 349:

In the last code snippet, this:

c = C.new

should be:

c = c.new

However, the reuse of the variable c, while legal, is confusing. A clearer version of the last two lines is:

c_instance = c.new c_instance.some_method


Page 383:

"an edition and an author" should be "a work and an instrument".


Page 383:

"authors and books" should be "instruments and works"


Page 397-398:

In the list of upcoming questions and methods, the question "Which customers have ordered this work?" is out of order, with respect to where it is in the subsequent discussion. Also, the definition of that method, when it appears, is wrong; it should be:

def ordered_by
  editions.map {|e| e.orders }.flatten.map {|o| o.customer }.uniq
end


Page 398:

The description of "Which publishers have published editions of the work?" mistakenly refers to the "editions" method used earlier as an example. In fact, the method defined here uses the Work#editions method, whereas the example was Composer#editions.


Page 398

"list of the latter" should be "list of the former".


Page 405:

"the %wf{" should be "the %w{"


Page 412:

In the second sentence of the third paragraph, the last word should be "value" rather than "key".


Page 418:

The check_out method examples should use open_orders, not orders. Using orders might work by coincidence, but the real point is to close the open orders.


Page 431:

In the last line: "The decision not to do so" should be "The decision to do so".


Page 445:

"set_customer" should be "get_customer".


Page 451:

In the last sentence, "rankings_things" should be "thing_ranking".


Page 443:

"set_customer" should be "get_customer".


Typos

Page xiv, Table of Contents:

Chapter 12 heading is run together.


Page 19:

In the sentence, "When you run the same Ruby snipped...", "snipped" should be "snippet".


Page 51:

In the "welcome" method, "def" should be indented two spaces from the left.


Page 168:

"The answer is, "... has extra quote single at the end that ruby would not output


Page 186:

The code output "This is method 'x'" should have a period: "This is method 'x'."


Page 191:

Missing space after period in: '... local scope.Note that ...'


Page 204:

Use puts rather than print for the code sample, so that the methods names will be displayed clearly and not run together.


Page 213:

In the code at the top, the mdash should be two single dashes.


Page 263:

In Table 10.2, the string in the last cell in "Example" column should not have a space at the beginning.


Page 298, Table 11.1:

In the phrase "True if the array includes items; false otherwise", "items" should be "item".


Page 323, Listing 12.2:

The first two print statements are missing trailing spaces after the colons.


Page 323, Listing 12.2:

In both lines that end with:

was:"

there should be a space between the colon and the quotation mark.


Page 327, Table 12.1:

Last column, second-to-last cell, there should be a period between "earth" and "\n".


Page 361:

In the "Tip", @pages should be @recipes.


Page 374:

In the tip, "specific method" should be "specific methods".


Page 419:

"or whatever you want to sent" should be "or whatever you want to send"


Page 435, Table 16.3:

Last entry in first column should be main/_favorites.rhtml (not .shtml).