Learning Ruby

Errata for Learning Ruby

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. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
Printed
Page 7
2nd ruby command from the top

Hi, When I type in the command ruby -e "puts 'Hello, Matz!'" I get the following error -bash: !'": event not found Cheers Mike

Note from the Author or Editor:
Just invert "/'. Should be: ruby -e 'puts "Hello, Matz"'

David Harrison  Jul 11, 2009 
Printed
Page 10
The Tk Toolkit

After a lot of trying (5 hours, over 2 days) and searching online I cannot get this to work at all. I have followed literally every example out there and I cannot get this to work. How do I get the Tktoolkit to work? Thanks, TJ

Note from the Author or Editor:
The section with the heading "The Tk Toolkit" should be removed from page 10 of the book because (1) the example does not work readily; (2) it requires more explanation than is warranted for a first chapter on the subject.

Anonymous  Jun 14, 2013 
Printed
Page 13
irb 80 % 60

Well... 80 percent of 60 is not 20. BUT 80 modulo 60 IS. I am not sure if that is what it is doing... but some clarification would be awesome. -TJ

Note from the Author or Editor:
I have added a clarifying sentence to the 2nd edition. Instead of: You can do some simple math: It now reads: You can do some simple math, such as addition (_+_), multiplication (_*_), divsion (_/_), subtraction (_-_), and modulo (_%_): This rewritten sentence could be added to a reprint as well (it is not dependent on Ruby 2.0).

Anonymous  Jun 14, 2013 
Printed
Page 14
2nd paragrah from the bottom

"is well-written and as complete it could possibly..." probably intended to be-- "is well-written and as complete <<as>> it could possibly..."

Anonymous    Aug 01, 2007
Printed
Page 18
Mid-page

It should be noted the the One-Click Installer does not include the Tcl/Tk library (among others) and you will have to download them separately. Because of this, I prefer to install Ruby on Windows using instructions in the next section.

Anonymous   
Printed
Page 23
last line of text on page

http://www.oreilly.com/catalog/learningruby gives a 404 error

Note from the Author or Editor:
Correct. The URL should be http://oreilly.com/catalog/9780596529864/

Anonymous   
Printed
Page 27
fourth paragraph

Here is another form. This block comment conceals several lines from the interpreter with =begin/=end: The correction should be "Here is another form. This block comment conceals several lines from the interpreter with =begin/=end (without any leading spaces or tabs:" This is not a serious problem but an inadvertent space or tab will create an error msg.

Note from the Author or Editor:
Yes, I like this change. Here is the sentence you should replace it with: "Here is another form. This block comment conceals several lines from the interpreter with =begin/=end (without any leading spaces or tabs):"

Anonymous   
Printed
Page 36
Return Values, numeral 3

The line says "Now assign method matz to the variables output and puts output" I believe it should instead read "Now assign method matz to the variable output and puts output" There's only one variable (output) and 'puts output' is a command, not a variable.

Note from the Author or Editor:
This errata is correct. The word "variable" should be singular, not plural.

Anonymous  Jan 17, 2010 
Printed
Page 48
1st paragraph

There is an extra "END" on this IF statement while the previous sentence clearly tries to explain that the keyword "END" is mandatory. " In addition, you don't have to use end if you write this code all on one line, like so: x - 256 if x == 256 then puts "x equals 256" end "

Note from the Author or Editor:
Change this sentence: "In addition, you don't have to use end if you write this code all on one line, like so:" To this: "In addition, you can write this code all on one line, like so:"

Anonymous   
Printed
Page 50
1st paragraph

In reference to an if / else construct, the text reads: The 'else' keyword gives 'if' an escape hatch. In other words, if the 'if' statement does not evaluate true, the code after 'else' will be executed, and if 'if' evaluates 'false', the code after 'else' is ignored. Should probably be something like: The 'else' keyword gives 'if' an escape hatch. In other words, if the 'if' statement does not evaluate true, the code after 'else' will be executed, and if 'if' evaluates 'true', (the code after 'if' is executed and) the code after 'else' is ignored.

Note from the Author or Editor:
Yes. Use the sentence given, except drop the parens.

Anonymous   
Printed
Page 50, 51
The tighter elsif code on Pg 50 and case code in Pg 51

Code on Page 50: ----------------- lang = :es if lang == :en: print "dog" elsif lang == :es: print "perro" elsif lang == :fr: print "chien" elsif lang == :de: print "hund" else puts "no language set; defaut = dog." end Code on Page 51: ------------------ ang = :fr dog = case lang when :en: "dog" when :es: "perro" when :fr: "chien" when :de: "Hund" else "dog" end These codes will work fine with Ruby 1.8.6 - p287 but will fail using Ruby 1.9.1. To make them work for both version, do not use the colon after the symbols, use the semi-colon or keyword "then" instead as follows: Code on Page 50: ----------------- lang = :es if lang == :en; print "dog" elsif lang == :es; print "perro" elsif lang == :fr; print "chien" elsif lang == :de; print "hund" else puts "no language set; defaut = dog." end Code on Page 51: ------------------ ang = :fr dog = case lang when :en; "dog" when :es; "perro" when :fr; "chien" when :de; "Hund" else "dog" end

Note from the Author or Editor:
He is correct, and both : and ; will work with 1.8.6, so lets just change the code as he suggests: Code on Page 50: ----------------- lang = :es if lang == :en; print "dog" elsif lang == :es; print "perro" elsif lang == :fr; print "chien" elsif lang == :de; print "hund" else puts "no language set; defaut = dog." end Code on Page 51: ------------------ ang = :fr dog = case lang when :en; "dog" when :es; "perro" when :fr; "chien" when :de; "Hund" else "dog" end

Murugappan Ramanathan  Nov 28, 2009 
Printed
Page 51
6th paragra

code as in book. lang = :fr dog = case lang when :en: "dog" when :es: print "perro" when :fr: print "chien" when :de: print "hund" else print "dog" end Hello,, besides the symbols ending with semi colon for ruby 1.9.1 or later which some one else also mentioned and helped me. You also need to write print to get output to screen code if you want output lang = :fr dog = case lang when :en; print "dog" when :es; print "perro" when :fr; print "chien" when :de; print "hund" else print "dog" end

Note from the Author or Editor:
lang = :fr dog = case lang when :en; print "dog" when :es; print "perro" when :fr; print "chien" when :de; print "hund" else print "dog" end

Anonymous  Oct 09, 2011 
Printed
Page 53
At the end of page, example of cash and sum

This is a logic error of how to use the variable sum. The author did not explain how to use the variable sum. I do not believe the variable sum is used in the calculation.

Note from the Author or Editor:
[Code should read:] cash = 100_0000.00 cash += 1.00 while cash < 1_000_000.00 # underscores ignored

Anonymous  Jun 24, 2009 
Printed
Page 65
5th para, 1st bullet

quote: hay == nicolay # => false ... ...You could also apply the eql? method and get the same results, though eql? and == are slightly different: [bullet] == returns true if two objects are Strings, false otherwise end quote. The first bullet is wrong as your own example "hay == nicolay" shows. See corelib.ruby, which defines == like this: "Equality?If obj is not a String, returns false. Otherwise, returns true if str <=> obj returns zero." Also your examples don't show any difference between "==" and ".eql?", since "hay.eql?" also returns false.

Note from the Author or Editor:
First bullet should say: == returns false if right operand is not a string. Otherwise, returns true if str <=> obj returns zero. "str <=> obj" should be formatted as code.

Anonymous   
Printed
Page 68
last code sample of section 4.5.4 - The delete method

This applies to the Safari online version of the book as of May 13, 2008. The example code doesn't generate the given output: "That's all folks".delete "abcdefghijklmnopqrstuvwxyz", "^ha" # => "haa" The .delete method will only delete the lowercase letters, excepting "h" and "a". It will not delete the uppercase letters ("T") or the punctuation (space and single quote), so the result is "Tha' a ", not "haa".

Note from the Author or Editor:
Change line of code to: "That's all folks".delete "abcdefghijklmnopqrstuvwxyz", "^ha"=> "Tha' a "

Anonymous   
Printed
Page 74, 75
Code examples

The code examples using grep do not work in Ruby 1.9.1. The code must be changed to: ex: pg 74 bottom of page opening.lines.grep(/men/) in order to produce the shown output. Similar changes must be made on the examples on pg 75 in order to produce the show output.

Note from the Author or Editor:
Change as specified. In the intro line, include "(1.9.1)" at the end of the line.

Anonymous  Dec 23, 2009 
Printed
Page 75
Last three paragraphs

The author provides this regular expression: phone.grep(/[\(\d\d\d\)]?\d\d\d-\d\d\d\d/) This is erroneous and does not work in the way the author explains. In particular, the square brackets around the area code indicate a character class, not a subexpression. Consequently, the supplied regular expression will match strings like '(123-4567' or '1123-4567' or ')123-4567'. In the last paragraph on the page (and continuing onto page 76) the author states, "The area-code pattern is surrounded by [ and ] so that the ? operator applies to the entire area code.Either form of the phone number, with or without the area code, will work." This is incorrect. Also, without any anchoring, the supplied expression will match things like '123-123123123123'. A better expression would have been: phone.grep( /\b(\(\d\d\d\))?\d\d\d-\d\d\d\d\b/ )

Note from the Author or Editor:
phone.grep(/^(\(\d{3}\))?\d{3}-\d{4}$/)

Jeremy Madea  Jul 14, 2012 
Printed
Page 82
2nd block of command line examples

The example "12.quo 5" does not return 2.4, it returns Rational(12, 5) To obtain that the example should be "12.0.quo 5.0"

Anonymous   
Printed
Page 91
Example 5-3

This may be an issue since I am using Ruby 2.0.0p195 When I type in list_primes = Prime.new I get the following error- Prime::new is obsolete. use Prime::instance or class methods of Prime. Thus I went with list_primes = Prime.instance and all is well! Not sure if that is the RIGHT way, but it does seem to work...

Note from the Author or Editor:
This error is confirmed and will be corrected in the 2nd edition which will document 2.0.0. But this code is correct for the older version used in the current book.

Anonymous  Jun 17, 2013 
Printed
Page 96
After 1st paragraph

irb(main):008:0> digits = Array(0..9) => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] not [1, 2, 3, 4, 5, 6, 7, 8, 9]

Anonymous   
Printed
Page 99
2nd-last paragraph

Under the code starting 'last_part = q3.concat(q4)', the book claims 'concat always returns a new array; it does not add elements to an existing array the way << does'. This seems incorrect; the elements are actually added to the original array, e.g. myarray=[1,2]; myarray.concat([3,4]); puts myarray.join(",")' #gives 1,2,3,4

Note from the Author or Editor:
I have deleted the assertion in the source (on Atlas). The next time the book is printed, it will no longer be in the text.

Tung Jin Chew  Nov 10, 2012 
Printed
Page 102
5th code block

I believe in the fifth code block on the page (the one right above the heading

Anonymous  Aug 07, 2008 
Printed
Page 102
5th code block

I believe in the fifth code block on the page (the one right above the heading "As a String", the elements "May", "June", and "July" should be in bold, not "June", "July", and "August".

Anonymous   
Printed
Page 119
middle of page

"run the program with these three files on the command line:" # argf.rb sonnet_29.txt sonnet_119.txt sonnet_129.txt should be ruby argf.rb sonnet_29.txt sonnet_119.txt sonnet_129.txt

Anonymous   
Printed
Page 123
2nd paragraph

There are two mistakes in the 2nd paragraph. Original text is

Note from the Author or Editor:
Please make the following correction to the 2nd and 3rd sentences in the 2nd paragraph on page 123. "The first argument is 1, which is the numeric file descriptor for standard output. Standard output can also be represented by the predefined Ruby variable $stdout [...]

Anonymous  Jul 01, 2009 
Printed
Page 215
Chapter 4 review question 9

to_a was the intended answer but split(//) will work too. Here is the difference: irb(main):001:0> "hello there".split(//) => ["h", "e", "l", "l", "o", " ", "t", "h", "e", "r", "e"] irb(main):002:0> "hello there".to_a => ["hello there"]

Anonymous