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.
| Version |
Location |
Description |
Submitted By |
| Safari Books Online |
all
all |
The book seems never to mention the RUBYLIB environment variable (except once in the 10.5 Security chapter, but it doesn't explain what it is, there or elsewhere). This is a crucial piece of information and should not be omitted. Modification of RUBYLIB is a very important technique.
|
Anonymous |
| Printed |
Page 1,2,3
.nitems {|x| x > 2} # => 1: # of elts matching block (Ruby 1.9) |
And replace them with these:
[1,2,nil].nitems # => 2: number of non-nil elements (Ruby 1.8 only)
[1,2,nil].count(nil) # => 1: # of nils (Enumerable method in Ruby 1.9)
|
Anonymous |
| Printed |
Page 1,2,3
.count {|x| x > 2} # => 1: # of elts matching block (1.9) |
|
Anonymous |
| Printed |
Page 3
first code line |
The comment to the first code line on page 3 says:
"true is a the singleton instance of TrueClass"
Should this be either "true is a singleton instance..." or "true is the singleton instance..."?
|
Sanders Kleinfeld |
| Safari Books Online |
5.1.2
near end of section |
In section 5.1.2, the third column of the three examples showing how to express an if structure:
(
line1
line2
) end if expression
...the word "end" is a mistake and should be deleted.
|
Anonymous |
| Printed |
Page 6
first paragraph |
In the last line of the first paragraph on page 6, should "singletonmethods" be "singleton methods"?
|
Sanders Kleinfeld |
| PDF |
Page 14
Second group of examples |
"enviroment" should read "environment".
|
Leo Wong |
| Printed |
Page 20
Top |
(Found in the 12/08 edition; haven't examined other editions.)
The line "@grid = @grid.dup" in the dup method defined in the Sudoku solver's Puzzle class doesn't assign to the new Puzzle object a new duplicate of the @grid array. Instead, the original Puzzle object is assigned a new duplicate @grid, and the original @grid has been moved to the new Puzzle object. Although this may not cause a problem in the context of the Suduko solver, the technique seems misleading and potentially risky.
Here's test code that demonstrates the problem:
class Puz
def initialize(grid)
@grid = grid
end
def dup
copy = super
@grid = @grid.dup
copy
end
def grid_objid
@grid.object_id
end
end
#----------------------
pz = Puz.new("xyzzy")
puts "pz grid object id is: #{pz.grid_objid}"
pz2 = pz.dup
puts "pz grid object id is now: #{pz.grid_objid}"
puts "pz2 grid object id is: #{pz2.grid_objid}"
|
Steve Eppley |
| Printed |
Page 26
2.1.1 |
The line:
x = "#This is a string" # And this is a comment
...should correctly read:
x = "#This is a string" # And this is not a comment
|
Anonymous |
| Printed |
Page 26
2.1.1 |
The line:
y = /#This is a regular expression/ # Here's another comment
...should correctly read:
y = /#This is a regular expression/ # And this is also not a comment
|
Anonymous |
| Printed |
Page 27
First code in section "Test Helpers" |
from:
require File.dirname(__FILE__) + '/test_helpers'
to:
require_relative 'test_helpers'
|
Jan Friedrich |
| Printed |
Page 52
2nd paragraph |
The following sentence...
After these lines have been read, the three string literals are concatenated into one.
...should also indicate that the the string concatenation is joined by newlines...
After these lines have been read, the three string literals are concatenated into one, joined by newlines (
).
|
Anonymous |
| Printed |
Page 53
End of 3.2.1.6 |
The code example...
listing = Kernel.`(listcmd)
...is missing a closing `, but in either case (with or without a closing `) results in errors:
>> listcmd = 'ls'
=> "ls"
>> listing = Kernel.`(listcmd)
`# had to enter closing ` to proceed
SyntaxError: compile error
(irb):46: unterminated string meets end of file
from (irb):46
from :0
>> listing = Kernel.`(listcmd)`
SyntaxError: compile error
(irb):47: syntax error, unexpected tXSTRING_BEG, expecting $end
from (irb):47
from :0
|
Anonymous |
| Printed |
Page 56
bottom |
Footnote marked with asterisk should appear on previous page, page 55.
|
Todd Shandelman |
| Printed |
Page 57
3rd line |
s[s.length] = ?! succeeds in Ruby 1.9. The book states it is an error.
irb(main):001:0> s = 'hello'
=> "hello"
irb(main):002:0> s[s.length] = ?!
=> "!"
irb(main):003:0> s
=> "hello!"
irb(main):004:0>
$ ruby --version
ruby 1.9.1 (2008-12-16 revision 20770) [i686-linux]
|
James Ravn |
| Printed |
Page 66
5th paragraph, not counting code insets |
Paragraph states "Note that these operators are not transitive: a|b is not the same as b|a, for example."
You're confusing "transitive" with "commutative." "Transitive" refers to relations like "<", and states, e.g. that (a < b && b < c) => (a < c).
|
Andy Lowry |
| Printed |
Page 68
bottom |
Footnote at bottom of page 68 should appear on previous page, page 67.
=====================================================================
Note: My version of the book says:
Printing History: Jan. 2008: First edition.
|
Todd Shandelman |
| Printed |
Page 114
Section 4.6.13, 3rd paragraph, 1st sentence. |
typo: "operfators" should be "operators"
|
Roger Smith |
| Printed |
Page 127
Section 5.2.1, 2nd paragraph (not counting code blocks), 2nd sentence |
"...between the do and the end keyword."
'keyword' is in constant width bold font. 'keyword' should be in the normal prose font.
|
Roger Smith |
| PDF |
Page 157
Bullet point 4, 2nd paragraph |
The relevant paragraph is
"raise accepts a string as its optional second argument. If a string is specified, it is passed to the exception method of the first argument. This string is intended for use as the exception message."
The first sentence is, I believe, misleading. raise accepts any object, which may be subsequently inspected. I've found this behaviour extremely useful.
An irb session, tested on both Ruby 1.8 MRI and 1.9 MRI, illustrates.
irb(main):001:0> class Foo; attr_accessor :bar; end
=> nil
irb(main):002:0> f = Foo.new
=> #<Foo:0x3b4ea8>
irb(main):003:0> f.bar = 10
=> 10
irb(main):004:0> begin; raise RuntimeError, f; rescue => e; puts e.message.bar; end
10
=> nil
Regards
Paul
|
Paul Carey |
| Printed |
Page 208
2nd code in section 6.8.3 |
from:
module Functional
.... omission....
# Example:
# product = lambda {|x,y| x*y}
# doubler = lambda >> 2 <== here
to:
module Functional
.... omission....
# Example:
# product = lambda {|x,y| x*y}
# doubler = product >> 2 <== here
|
Anonymous |
| Printed |
Page 208
2nd line |
double = lambda {|x| product(2,x) }
should be
double = lambda {|x| product[2,x] }
|
Christian Campbell |
| Printed |
Page 232
general |
And the PDF. Also p. 237.
I think it might be worth mentioning that a method on a superclass can call *private* subclass methods if the object is an instance of the subclass (since the superclass method is inherited).
E.g.,
class Super
def full_name
"#{first} #{last}"
end
end
class Sub < Super
attr_reader :first, :last
def initialize(first, last)
@first, @last = first, last
end
private :first, :last
end
s = Sub.new("John", "Norman")
puts s.full_name
In other words, "private" is all about self, and not allowing a receiver. I think the language about access from subclasses is a bit misleading.
|
John Norman |
| Printed |
Page 238
Code |
Redundant semicolon. (Also on page 239.)
|
Anonymous |
| Printed |
Page 238
2nd paragraph of 7.3.3 |
super doesn't just look at superclasses for chaining. It can also chain to methods inherited from modules. And a singleton method defined on an object can use super to chain to an instance method defined by the class of the object.
|
David Flanagan
|
| Printed |
Page 240
3rd paragraph from bottom |
In "is it actually something different" transpose "it" and "is".
|
Anonymous |
| PDF |
Page 251
4th line of 7.5.3 |
Change:
include 'Math' # The Math namespace can be included
To:
include Math # The Math namespace can be included
(This was already reported for 'printed' and 'other digital', so why is this error still present in the PDF?)
|
TPReal |
| PDF |
Page 255
first line of 7.6.2 |
The first four words of the section 7.6.2 are: 'load and require execute' (where 'load' and 'require' are ruby function names, in monospace font). Those four words are not separated by spaces.
|
TPReal |
| Printed |
Page 261
2nd Paragraph |
The paragraph says:
"Class objects are special: they have superclasses. The eigenclasses of
class objects are also special: they have superclasses, too. The
eigenclass of an ordinary object stands alone and has no superclass."
Both the eigenclass of a class object and the eigenclass of an ordinary object have a superclass. If not then sending a message to an ordinary object would end up invoking method_missing.
I think that the paragraph should read:
"Class objects are special: they can have subclasses. The eigenclasses of
class objects are also special: they can have subclasses, too. The
eigenclass of an ordinary object can have neither a subclass, nor any other instance except that single ordinary object. If an ordinary object with an eigenclass is duplicated with the Object#dup method, the duplicate will not acquire any of it's singleton methods. If it is cloned with the Object#clone method, the result will get an eigenclass which is a duplicate of the original objects eigenclass, so that each eigenclass has but a single instance."
The following ruby code (which behaves identically on Ruby 1.8.6, 1.8.7 and 1.9.1) illustrates the above:
module Kernel
def eigenclass
class << self;self;end
end
end
class TestClass
def bar
:bar
end
def self.foo
:foo
end
end
t = TestClass.new
def t.gorp
:gorp
end
p t_eigenclass = t.eigenclass # => #<Class:#<TestClass:0x232d0>>
p t_eigenclass.superclass # => #<Class:TestClass>
p t.bar # => :bar
p t.gorp # => :gorp
p t_dup = t.dup
p t_clone = t.clone
p t_clone.respond_to?(:gorp) # => true
p t_clone.eigenclass == t_eigenclass # => false
p t_dup.respond_to?(:gorp) # => false
p t.class.foo # => :foo
p t.eigenclass.foo # => :foo
|
Rick DeNatale |
| Printed |
Page 261
2nd paragraph |
The sentence: "The eigenclass of an ordinary object stands alone and has no superclass" is not correct. The description of method lookup in this section is correct, but the details about superclasses of eigenclasses strays into messy implementation-dependent behavior.
See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/336490 for some discussion.
|
David Flanagan
|
| Printed |
Page 271
paragraph after exemple code in section 8.3.1 |
The book says "eval can alter the value of instance variables that already exist. But any new instance variables it defines are local to the invocation of eval and cease to exist when it returns."
This should say local variables instead of instance variables in both cases.
Eval can alter INSTANCE variables, whether they exist or not. If an instance variable is set by eval, it will be created in the receiver of eval, just as it would be if this were done by executing a method on an object for which this is the first assignment to the instance variable.
irb(main):001:0> eval("self")
=> main
irb(main):002:0> self
=> main
irb(main):003:0> eval("@x = 1")
=> 1
irb(main):004:0> @x
=> 1
|
Rick DeNatale |
| PDF |
Page 277
2nd paragraph of 8.5 |
Change this:
Recall that class methods are inherited, so that the an inherited method will be ...
To this (remove the word 'an'):
Recall that class methods are inherited, so that the inherited method will be ...
|
TPReal |
| PDF |
Page 278
4th paragraph |
In the part about the method_added hook, it is said:
(...) there is no way to tell whether the named method was added to the class that defines method_added or whether it was added to a subclass of this class.
Next, a workaround solution for this problem is given. But in fact no workaround is needed - the class to which the new method was added is stored in self when inside the hook method. A simple code to demonstrate it:
class A;def A.method_added(m);p [self,m];end;end
class B<A;end
class A;def q;end;end # prints [A, :q]
class B;def w;end;end # prints [B, :w]
|
TPReal |
| PDF |
Page 288
first line of 8.10.1 |
Missing space. Change this:
Example 8-6defines ...
To this:
Example 8-6 defines ...
|
TPReal |
| PDF |
Page 304
first line of 9.1 |
Missing space. Change this:
Chapter 3explained ...
To this:
Chapter 3 explained ...
|
TPReal |
| PDF |
Page 305
near middle of the page |
Change this line:
s.start_with? "hell" # => true. Note singular "start" not "starts"
To this:
s.start_with? "hell" # => true. Note "start" not "starts"
(Already marked as corrected in 'printed' and 'other digital' versions, but still present in PDF.)
|
TPReal |
| Printed |
Page 307
3rd paragraph, first code section |
Shows:
"a".upto("e") {|c| print c } # Prints "abcde. upto iterator based on succ.
Should show:
... # Prints "abcde"
|
Anonymous |
| Printed |
Page 321
Second code section |
Says:
0.odd? # => false
Should also say:
0.odd? # => false (Ruby 1.9)
|
Anonymous |
| Printed |
Page 322
First sentence |
Says:
The Float class defines a methods ...
Remove the word "a".
|
Anonymous |
| PDF |
Page 329
first full paragraph on this page |
Missing space. Change this:
each_sliceand each_cons ...
To this:
each_slice and each_cons ...
|
TPReal |
| Printed |
Page 335
in the middle |
The nitems method of Array has been removed in Ruby 1.9.
Delete the following two lines:
[1,2,nil].nitems # => 2: number of non-nil elements
|
Anonymous |
| PDF |
Page 359
3rd line of 1st code sample |
The encoding name is written as Encoding::UTF-8 and should be Encoding::UTF_8 (underscore and not dash).
|
TPReal |
| PDF |
Page 361
4th line from the top |
In this sentence: 'If you specify the empty string "" as the line terminator, ...', the empty quote is in the normal text font, and it should be in the monospace font, as it is a piece of Ruby code.
|
TPReal |
| Printed |
Page 364
3rd paragraph |
Output record separator is $ not $/
|
Anonymous |
| Printed |
Page 367
last paragraph in 9.8.1, first sentence |
Change:
This client code for use...
To:
This client code is for use...
|
Anonymous |
| Printed |
Page 384
3rd paragraph |
Section 9.9.7.1 claims "The way to avoid this kind of deadlock is to always lock resources in the same order. If the second thread locked m before locking n, then deadlock would not occur."
This is false as tested by the code:
require 'thread'
m,n = Mutex.new, Mutex.new
t = Thread.new {
m.lock
puts "Thread t locked Mutex m"
sleep 1
puts "Thread t waiting to lock Mutex n"
n.lock
}
s = Thread.new {
m.lock
puts "Thread s locked Mutex n"
sleep 1
puts "Thread s waiting to lock Mutex m"
n.lock
}
t.join
s.join
This returns:
Thread t locked Mutex m
Thread t waiting to lock Mutex n
deadlock 0x10019c638: sleep:- - rubytest.rb:14
deadlock 0x1001b8360: sleep:J(0x10019c638) (main) - rubytest.rb:22
rubytest.rb:22:in `join': Thread(0x1001b8360): deadlock (fatal)
from rubytest.rb:22
|
Leo Sternlicht |
| Printed |
Page 390
Last bullet before 10.1 |
Change:
... SQL injection and similar attacks on with ...
To:
... SQL injection and similar attacks with ...
|
Anonymous |