Errata

Ruby in a Nutshell

Errata for Ruby in a Nutshell

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
Printed Page 1,3,5
|[1,2,3] # => [1,3]

Anonymous   
Printed Page 1,3,5
|[2,4,6] # => [1,2,3,4,5,6]

should in fact read:

Anonymous   
Printed Page 1,3,5
&[1,2,3] # => [1,3]

Anonymous   
Printed Page 2
6th paragraph

puts 1*2

should be

puts i*2

Anonymous   
Printed Page 2
6th paragraph

end # prints 2,3,4,8,10

should be

end # prints 2,4,6,8,10

Anonymous   
Printed Page 2
paragraph 7

i %2 == 0 fails

either i%2 or i % 2 works

This raises questions in my mind about whitespace and when it is required or
optional. Tested with irb 1.6.6 on Linux.

Anonymous   
Printed Page 2
6th paragraph

Under the iterators section the each block has 'puts 1*2 instead of 'i*2'.

Kenneth Lombardi  Jan 10, 2016 
Printed Page 3
in "portable" section

add Mac OS to list of platforms supported

Anonymous   
Printed Page 4
second line

if /Ruby/ =~ line
should be
if line =~ /Ruby/

As written, the expression tests to see if the pattern /Ruby/
contains the input line, which should always be false. (And
since line is a String, it will be converted to a regular
expression, which makes the outcome of =~ hard to predict.)

On the other hand, line =~ /Ruby/ returns true if the input
line matches the expression -- a useful idiom which is no
doubt what was intended.

Anonymous   
Printed Page 5
Explanation of the -h command line argument

The line states that -h is equivalent to -help, it should be --help. Note the t
wo '-' signs, not the one as shoown in the book.

Anonymous   
Printed Page 6
13th entry

The -X switch for Ruby is described as being synonmous with -c here, but the -C
(capital) switch is correct.

Anonymous   
Printed Page 9
Reserved Words list

Are the words raise, public, protected, and private not Reserved Words?
I would think that at least 'raise' is.

Anonymous   
Printed Page 10
Line above table 2.1

"...slash notation can be represent unprintable..."

should be

...slash notation can represent unprintable...

Anonymous   
Printed Page 12
'General delimited string array'

The paragraph gives the %W command (note the uppercase). Ruby only has %w (lowe
rcase) and will error if you use the uppercase version.

The example code that follows gets it right with the lowercase version

Anonymous   
Printed Page 17
Parallel Assignment, first paragraph of section

"... If the last right-side expression is preceded by *, the array elements of
expression are expanded in place before assignment." is ambiguous.

The second use of "expression" should be "the expression."

Anonymous   
Printed Page 18
paragraph 1

Operator precedence is defined but operator function is not.

For instance, the % operator used in the example in paragraph 7 on page 2 is "mod".
This is not in the index, nor anywhere else in the book. Operator functions should be
defined somewhere.

This comment applies to all operators.

Anonymous   
Printed Page 21
line 22

identifier1 identifier2 {|varizable| code}
should be |variable|

Anonymous   
Printed Page 22
Section "Singleton methods"

The example given on p. 23 just before the section "Method operations"

"
a = "foo"
def a.foo
...
"

is at the wrong place (IMHO). It should be just before the last paragraph on p. 22.
(That is after "...while specifying a receiver.
" and before "Defines a singleton method..."

Anonymous   
Printed Page 27
under "break Statement"

It says that break can be used to terminate while and until loops, but it can also be
used to terminate for loops.

Anonymous   
Printed Page 42
Explanation of "proc { |x| ... } and proc

Should be
"See Lambda"

(insert "b")

Anonymous   
Printed Page 44
Example in Explanation of "sprintf(fmt...)

Second last example should be

sprintf("%8s", "hello") # => " hello" (space padded)

(is " hell")

Anonymous   
Printed Page 52
Description of s.include?

Instead of

Returns true if str is present in s.

you should read

Returns true if x is present in s.

Anonymous   
Printed Page 54
Examples of s.split

The third and fourth examples of s.split have the wrong result:

"a:b:c:::".split(/:/, 4) # => ["a", "b", "c", "::"]
"a:b:c:::".split(/:/, -1) # => ["a", "b", "c", "", "", ""]

Anonymous   
Printed Page 55
3rd and 2nd last explanation "s.succ" and "s.succ!"

"s.succ" and "s.succ!" appear twice in the list.
The second entry of both is not in alphbetical order and should be removed.

Anonymous   
Printed Page 57
Regexp section, first word in first paragraph

The first word reads "Regex" (in a code typeface) which should read "Regexp".

Anonymous   
Printed Page 57
Regexp section, first sentence

The sentence is:
"Regex is object representation of regular expression."

Should be something like
"Regexp is the object representation of a regular expression."
or
"Regexp is the object representation of regular expressions."
(I'm not a native English speaker, but there seem to be some articles missing...)

Anonymous   
Printed Page 59
arr& method

Under the arr& method beneath the Instance Methods, section, the
following code:

Anonymous   
Printed Page 60
Third entry

The description of arr[n..m], arr[n,len] is

Returns a partial string

But this is about arrays and not strings and should read

Returns an array slice

In Perl parlance, there is probably a Ruby way of saying this, sub array or something.

Anonymous   
Printed Page 61
arr.join section

"bar" and "world" are missing closing quotes.

Anonymous   
Printed Page 64
Explanation of "arr.slice(n), arr.slice(n..m), arr.slice(n, len)"

In the book:
Deletes the partial string specified and returns it.

Should be "array", not "string". (This also holds for arr.slice!, BTW)
The example is about a string, too.

Anonymous   
Printed Page 67
update method example

The h.update(hash) example contains one error:
h1["c"] should contain 400 instead of 300 as the example says

Anonymous   
Printed Page 69, 70
p. 69: 3rd paragraph, under Numeric head, p. 70: last para, under 'In

teger' head;
Numeric is an abstract class, so you should not instansiate this class.
Integer is an abstract class, so you should not instansiate this class.

Should be:

"Instantiate"

Anonymous   
Printed Page 70
Examples of n.remainder

The examples of n.remainder contain also the examples of n.modulo.

Anonymous   
Printed Page 70
First instance methods of Numeric class

The i&int, i|int and i^int bitwisw operation should be moved to the paragraph above
(here only inversion is listed).

Anonymous   
Printed Page 71
i.step paragraph (end of page)

The description of i.step is not very clear, neither are the var names.

An example could be:

i.step(final, step) {|i| ...}
Iterates the block from i to final, either upwards or downwards, adding step each
time.

Anonymous   
Printed Page 71
i.times description

The description of i.times is not very clear. Something like the following should be
added:

Iterates the block i time, passing a value from 0 to i-1 to the block.

Anonymous   
Printed Page 72
i.times description

The description of i.times is not very clear. Something like the following should be
added:

Iterates the block i time, passing a value from 0 to i-1 to the block.

Anonymous   
Printed Page 73
3rd line

"internel" should be "internal".

Anonymous   
Printed Page 75
Section: "Class Methods", Explanation of "IO::foreach( path) {| x| ...}"

In the example code:
print n, ":", lib

should be
print n, ":", line

Anonymous   
Printed Page 76
Section: "Instance Methods", Explanation of "io.each {| x| ...}"

In the example code:
print n, ":", lib

should be
print n, ":", line

Anonymous   
Printed Page 82
Method definition of f.chmode(mode)

The book says "f.chmode(mode)". It should be "f.chmod(mode)".

Anonymous   
Printed Page 98-99
remove_method and undef_method examples

The first line of the two examples ('class Foo') is not aligned with the others.

Anonymous   
Printed Page 108
Definition of t.min

t.min should return 0-59.

Anonymous   
Printed Page 112
The s.peeraddr definition of IPSocket

The example given after the definition is that of the s.recvfrom method. There
is no peeraddr example.

Anonymous   
Printed Page 125
'Class Methods' section

WRONG: Net::POP3::new, Net::POP3::start, and Net::POP::start use 80 as default port
to connect to.
CORRECT: They use 110 as default port.

Anonymous   
Printed Page 143
'Required Library' section

WRONG: 'GetoptLong' requires 'gettextfile' library.
CORRECT: It requires 'getoptlong' library, 'gettextfile' does not exist in Ruby
Standard Library.

Anonymous   
Printed Page 164
The MD5 example

The example says "requires 'md5'", but it should be "require 'md5'"

Anonymous   
Printed Page 173
1st paragraph

The entry stated will invalidate a user .emacs file.

Anonymous