Errata


Print Print Icon

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



Version Location Description Submitted By
Printed Page 75
Last code snippet

In all of the phone.grep examples (starting on p75, and continuing to p76), the area code is
incorrectly enclosed in square brackets, rather than parentheses. That example should read:

phone.grep(/((ddd))?ddd-dddd/) # => ["(555)123-4567"]

The examples will produce the output shown, because the area code segment is made optional with "?".
The remainder of the expression matches the remainder of the phone number ("123-4567"), and so an array
consisting of the phone string is returned, as shown. But the text implies that the regular expressions
shown match the ENTIRE number, which is not true.

Anonymous 
Printed Page 80
Figure 5-1

The diagram has quite a few errors:
- Rational is a child of Object, not Integer
- Complex is a child of Numeric, not Integer
- Float is a child of Numeric, and missing from the diagram

Anonymous 
Printed Page 102
2nd code example

months.insert(0, nil) does not replace "nil," insert() adds nil so the array looks like this:

[nil, "nil", "January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"]

Anonymous 
Printed Page 116
last two line on the page

I believe that...

dir.tell #=> "."
dir.read #=> 1

should be switched to...

dir.tell #=> 1
dir.read #=> "."

Anonymous 
Printed Page 120
top of page

link = page_content.scan(/<a class=l.*?"(.*?)").flatten

I think the "class=l" is in the code example erroneously, it prevents the code from running properly. I
solved it by taking it out.

Anonymous 
Printed Page 135
Example 9-12

One of the ternaries in the dice roll method of the Dice module, r1 = r_1>0?r_1:1; r2 = r_2>0?r_2:6, is
incorrect in that in over one million rolls a 12 is never obtained. While such results are not impossible,
statistically they qre highly unlikely. Re-writing the statements as r1 = r_1>0?r_1:6; r2 = r_2>0?r_2:6,
that is setting both r1 and r2 to 6 in the negative case solves the problem. Data follows:

with r1 = r_1>0?r_1:6 1000000 rolls
Frequencies
Actual Expected
two = 27909 0.028 0.028
three = 55540 0.055 0.056
four = 83132 0.083 0.083
five = 111112 0.111 0.111
six = 139029 0.139 0.139
seven = 166741 0.168 0.167
eight = 139193 0.139 0.139
nine = 110788 0.111 0.111
ten = 83264 0.083 0.083
eleven = 55388 0.054 0.056
twelve = 27904 0.028 0.028

with r1 = r_1>0?r_1:1 1000000 rolls
Frequencies
Actual Expected
two = 55501 0.056 0.028
three = 83259 0.083 0.056
four = 111443 0.111 0.083
five = 139386 0.139 0.111
six = 166769 0.167 0.139
seven = 166207 0.166 0.167
eight = 110925 0.111 0.139
nine = 83170 0.083 0.111
ten = 55552 0.056 0.083
eleven = 27788 0.028 0.056
twelve = 0 0.000 0.028

Anonymous 
Printed Page 135
Example 19.2

the method roll does not generate dice rolls from 2 to 12. it has more than 1 error. Results of a run of
3000 executions are shown 2 is generated 167 times, 11 generated 93 times, 12 never generated. Test code
provided below results.

2
167
3
271
4
325
5
403
6
514
7
487
8
369
9
231
10
140
11
93

Run code below and see what happens when the three methods are plugged into the main routine and are
called:

#!C:RailsInstantRails ubyin uby.exe -w

# Written by: David S. Banham
# Version : 1.0

# Create Test-case Count
TEST_CASES = 3000

# Create a hash representing the possible dice outcomes and initialize counts to 0
$roll=Hash.new(0)

# Three dice algorithms

# simplified version of algorithm on page 135
def roll_dice_lp_simple
r_1 = rand(6)
r1 = r_1>0?r_1:1
r1
end

# algorithm on page 135
def roll_dice_lp
r_1 = rand(6); r_2 = rand(6)
r1 = r_1>0?r_1:1; r2 = r_2>0?r_2:6
total = r1+r2
# puts "you rolled #{total}"
total
end

# correct simple dice roll algorithm
def roll_dice
rand(max=6) + 1
end

# Main Program plug in any algorithm and look at its results for
# a large number of rolls of the dice

puts Time.now.to_f
for i in 1..TEST_CASES
dice_value = roll_dice_lp
# puts dice_value
$roll[dice_value] = $roll[dice_value] +1
end

puts Time.now.to_f

puts"


"
puts $roll.sort
puts "

The End"

# End of Main Program

Anonymous 
Printed Page 152
middle

"a hint that Ruby is managing resources efficiently"...

NOT TRUE. if you say a = b
a.object_id and b.object_id all the time... a and b point to the same object. hence same object id.

Anonymous 
Printed Page 156
middle of page

Program example asks to load from http://www.wyeast.net/images/sunrise.jpg

site does not exist

Anonymous 
Printed Page 190
last paragraph

After following successfully all previous instructions

./script/generate scaffold address address

gives:

17:29:07 -> ./script/generate scaffold address address
exists app/controllers/
exists app/helpers/
create app/views/address
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/address.rb
create test/unit/address_test.rb
create test/fixtures/addresses.yml
error Before updating scaffolding from new DB schema, try creating a table for your model (Address)
17:29:20 ->

instead of what the book reports.

Anonymous