Errata

Ruby Cookbook

Errata for Ruby Cookbook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page xxv
2nd Paragraph

The paragraph does not appear to have been updated from the original version of the Ruby cookbook. It states that the recipes were tested with Ruby 1.8.4 and Rails 1.1.2, which seems a bit unlikely in 2015!

rorym  Mar 29, 2015 
1
not sure

In the "Representing Unprintable Characters" recipe, the word "mneumonic" appears. I think that should be "mnemonic."

Matt Hacker  Apr 04, 2016 
1.11
Section 1.11

"The prime library has the set of all prime numbers"

This is not possible as there are an infinite number of prime numbers, at best it can only contain all primes up to some number

Anonymous  Feb 17, 2017 
Printed, Page 28
3rd paragraph

algorithms is misspelled as "alogorithms"

O'Reilly Media
 
Mar 29, 2016 
Printed, Page 28
4th paragraph

Not sure if "with" should be in this sentence: This has meant that anything that breaks backward compatibility is being explored with in Ruby 3.

O'Reilly Media
 
Mar 29, 2016 
PDF, ePub Page 175
code in the Solution of 5.9. Sorting an Array by Frequency of Appearance

phenomenon:
code indentation error (wrong code indentation).
in the Solution section of 5.9. SOrting an Array by Frequency of Appearance section (page 175 of PDF), line 3 of code separates the "def" keyword and the function name "sort_by_frequency" into next line while line 3 and 4 of code "def sort_by_frequency" should be in a line.

why importance:
this code indentation errors are scattered all over the pages not only an above area. I ask for editor checking the code indentation.

expected:
all code in the book should be aligned correctly.



Anonymous  Oct 11, 2014 
PDF Page 195
the first and second code examples in theh bottom half of page

The tab/indentation formatting of the first code example appears to have not indented the first line: "empty = Hash.new" in line with the others.

Also - the second code example starting with "numbers" is offset to the left as well. At first I thought I was looking at coffeescript because of the indentation.

Ryan Grow  Dec 01, 2014 
PDF Page 195
4th paragraph

The text that reads:
"In Ruby 2.1, a new syntax was introduced...."
Should probably read:
"In Ruby 1.9, a new syntax was introduced...."

Ryan Grow  Dec 01, 2014 
PDF Page 329
last paragraph

There is one extra letter 't': "by calling Module#atttr_writer" should be "by calling Module#attr_writer"

Anonymous  May 08, 2016 
PDF Page 332
2nd paragraph and the code block below it

I found at least the following mistakes:

The second paragraph text refers to a class called CardinalNumber whereas the code block below it has a class called OrdinalNumber.

The first line of code in the to_s method:
delegate_s = __getobj_ _.to_s
should be
delegate_s = __getobj__.to_s

The if condition uses a variable called "to_check" that does not exist. I believe it should be "check" that is given a value on the previous line.

There are checks for numbers eleven (11) and twelve (12) but, for example, the numbers 111 and 112 don't work as expected. They return 111st and 112nd when they should 111th and 112th, respectively.

The case-when structure is missing a when statement for number three to get the suffix "rd". It is given as an example in the comment block before the class implementation.

Anonymous  May 08, 2016 
PDF Page 336
N/A

This is more like a minor technical inaccuracy and suggestion than a mistake per se.

Under the heading "Number conversion and coercion", it would be good to mention that methods to_i and to_f, and maybe others too, do not work well with non-numeric string input, i.e. on strings that don't represent numbers.

For example, 'abc'.to_i and 'abc'.to_f return zero and 0.0, respectively, which effectively hide an error that can cause hard-to-find bugs.

As easy as it is to use the method to_i, I think it should be mentioned that there is a better way to convert a string into an integer or float, for example, when accurate behavior is expected. The solution for that is to use Integer(str) or Float(str) that raise an exception if the string is not numeric.

Anonymous  May 08, 2016 
PDF Page 773
Profiling output of running sequence_counter.rb, at top of page.

The 7-column output display of the Ruby profiler is not what would actually result from running this Ruby script. The time column shows all zeros, for instance, when the text refers to different times.

Mark Hern  Feb 06, 2017 
Printed, Page 783
2nd paragraph

"And if you're not sucked into an mess..."

should be

"And if you're not sucked into a mess..."

O'Reilly Media
 
Mar 29, 2016