Ruby in a Nutshell By Yukihiro Matsumoto The unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification This page was updated April 01, 2003. UNCONFIRMED errors and comments from readers: (2) 6th paragraph; puts 1*2 should be puts i*2 (2) 6th paragraph; end # prints 2,3,4,8,10 should be end # prints 2,4,6,8,10 {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. {3} in "portable" section; add Mac OS to list of platforms supported {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. {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. {6} 13th entry; The -X switch for Ruby is described as being synonmous with -c here, but the -C (capital) switch is correct. [9] Reserved Words list; Are the words raise, public, protected, and private not Reserved Words? I would think that at least 'raise' is. (10) Line above table 2.1; "...slash notation can be represent unprintable..." should be ...slash notation can represent unprintable... (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 (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." (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. (21) line 22; identifier1 identifier2 {|varizable| code} should be |variable| {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..." {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. (42) Explanation of "proc { |x| ... } and proc; Should be "See Lambda" (insert "b") (44) Example in Explanation of "sprintf(fmt...); Second last example should be sprintf("%8s", "hello") # => " hello" (space padded) (is " hell") (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. (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", "", "", ""] {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. {57} Regexp section, first word in first paragraph; The first word reads "Regex" (in a code typeface) which should read "Regexp". (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...) {59} arr& method Under the arr& method beneath the Instance Methods, section, the following code: [1,3,5]|[1,2,3] # => [1,3] [1,3,5]|[2,4,6] # => [1,2,3,4,5,6] should in fact read: [1,3,5]&[1,2,3] # => [1,3] {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. {61} arr.join section; "bar" and "world" are missing closing quotes. {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. {67} update method example; The h.update(hash) example contains one error: h1["c"] should contain 400 instead of 300 as the example says (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" (70) Examples of n.remainder; The examples of n.remainder contain also the examples of n.modulo. (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). (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. (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. (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. (73) 3rd line; "internel" should be "internal". (75) Section: "Class Methods", Explanation of "IO::foreach( path) {| x| ...}"; In the example code: print n, ":", lib should be print n, ":", line (76) Section: "Instance Methods", Explanation of "io.each {| x| ...}"; In the example code: print n, ":", lib should be print n, ":", line [82] Method definition of f.chmode(mode); The book says "f.chmode(mode)". It should be "f.chmod(mode)". (98-99) remove_method and undef_method examples; The first line of the two examples ('class Foo') is not aligned with the others. {108} Definition of t.min; t.min should return 0-59. {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. [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. [143] 'Required Library' section; WRONG: 'GetoptLong' requires 'gettextfile' library. CORRECT: It requires 'getoptlong' library, 'gettextfile' does not exist in Ruby Standard Library. (164) The MD5 example; The example says "requires 'md5'", but it should be "require 'md5'" [173] 1st paragraph; The entry stated will invalidate a user .emacs file.