= Ruby逆引きレシピ 正誤表 2010/03/15版 == レシピ015 === p.033 誤 # プロンプトのタイトル文字列を"Ruby Recipe"にする 正 # プロンプトのタイトル文字列を"Ruby Recipe Sample"にする == レシピ020 === p.044 最後のコード例 誤 utf8_str = NKF::nkf('-Ew', str) 正 utf8_str = NKF::nkf('-Ew', euc_jp_str) == レシピ024 === p.056 誤 Fixnumクラスは31ビットの符号付き付き整数であり、表現可能な値の範囲は-1,073,741,824〜1,073,741,823です。 正 Fixnum クラスは C の long 型のビット数から1を引いたビット数 (8*sizeof(long) - 1) の符号つき整数です。そのため、表現可能な値の範囲はプラットフォームに依存して決定されます。long が32ビット長であるプラットフォーム上では Fixnum は31ビット符号付き整数となり、表現可能な値の範囲は-1,073,741,824〜1,073,741,823です。long が64ビット長であるプラットフォームでは Fixnum は63ビット符号付き整数となり、表現可能な値の範囲は-4,611,686,018,427,387,904〜4,611,686,018,427,387,903です。Fixnum は少なくとも31ビット長であることが保証されています。 == レシピ029 === p.067 一番最後のコード例 誤 require 'rubygems' require 'measure' require 'measure/length' 正 require 'rubygems' require 'measure/length' == レシピ040 === p.089 最後から2行目 誤 要素数が指定しなければ 正 要素数を指定しなければ == レシピ067 === p.134 のコード例 誤 templete 正 template == レシピ068 === p.136 decoder_factory.rb の self.create の case のインデント 誤 def self.create(file_type) case file_type when :mp3 MyMp3Decoder.new when :aac MyAacDecoder.new when :atrac3 正 def self.create(file_type) case file_type when :mp3 MyMp3Decoder.new when :aac MyAacDecoder.new when :atrac3 === p.136 最後の使用例 誤 decoder = decoder_factory.create(file_type) 正 decoder = DecoderFactory.create(file_type) == レシピ070 === p.139 誤 attr_reader :x, y 正 attr_reader :x, :y == レシピ082 === p.165 の最初のコード例 誤 def point(*args) 正 def point(args) == レシピ086 === p.173, p.174, p.175 のコード例 誤 context[:port] => 389 正 context[:port] = 389 誤 context[:lang] => "us" 正 context[:lang] = "us" == レシピ089 === p.183 コード例の一番最後 誤 "".empty? #=> false 正 "".empty? #=> true == レシピ097 === p.197 コード例の一番最後 誤 :encording => 'UTF-8' 正 :encoding => 'UTF-8' === p.199 コードの意図について 誤 user = User.find(1) user.login = "shimada" user.save! 正 user = User.find(1) user.login = "mrkn" user.save! == レシピ098 === p.202 3つ目のコード例 誤 Sequel('postgres://user:password@localhost/my_db') 正 Sequel.connect('postgres://user:password@localhost/my_db') === p.202 COLUMNのコード例 誤 DB = Sequel('sqlite://zipcode.sqlite3') 正 DB = Sequel.connect('sqlite://zipcode.sqlite3') == レシピ161 === p.261 1番目のコード例 誤 FancyIndexing => true) 正 :FancyIndexing => true) == レシピ133 === p.299 誤 では、次にこのタプルスペースを利用して複数のプロセスで分数処理をしてみます。 正 では、次にこのタプルスペースを利用して複数のプロセスで分散処理をしてみます。 == レシピ152 === p359 誤 XML Path Length (XPath) パージョン1.0 正 XML Path Length (XPath) バージョン1.0 (カタカナの「ば」が「ぱ」になっている) == レシピ154 === p364 誤 $ install libfreeimage-dev 正 $ apt-get install libfreeimage-dev == レシピ176 === p.425 test_team.rb 誤 require 'test/unit' 正 require 'test/unit' require 'person' require 'team' == レシピ178 === p.431 test_team_with_stub.rb 誤 require 'test/unit' require 'rubygems' require 'mocha' 正 require 'test/unit' require 'rubygems' require 'mocha' require 'person' require 'team' === p.432 test_team_with_mock.rb 誤 require 'test/unit' require 'rubygems' require 'mocha' 正 require 'test/unit' require 'rubygems' require 'mocha' require 'person' require 'team' == レシピ207 === p.496 最初の二つのコード例 誤 task :byebye 正 task :byebye do == レシピ218 === p.537 ,"nn" は不要 誤 puts ISeq.compile("puts 'Hello,VM'").disasm,"nn" 正 puts ISeq.compile("puts 'Hello,VM'").disasm == レシピ224 === p.551のdefine_lambda_alias.rbのコード例を2つの囲みに分離 誤 #### define_lambda_alias.rb # coding: UTF-8 methods = Kernel.private_instance_methods module Kernel alias λ lambda end sym = (Kernel.private_instance_methods - methods)[0] sym.encoding #=> # f = λ{ 1 + 2 } f.call #=> 3 f = __send__('λ'.intern) { 1 + 2 } f.call #=> 3 # 文字エンコーディングのみが異なる f = __send__('λ'.force_encoding('EUC-JP').intern) { 1 + 2 } #=> undefined method `λ' for main:Object (NoMethodError) # バイト列と文字エンコーディングの両方が異なる場合 f = __send__('λ'.encode('EUC-JP').intern) { 1 + 2 } #=> undefined method `??' for main:Object (NoMethodError) 正 #### define_lambda_alias.rb # coding: UTF-8 module Kernel alias λ lambda end 以下は別枠に分離 # coding: UTF-8 methods = Kernel.private_instance_methods require 'define_lambda_alias' sym = (Kernel.private_instance_methods - methods)[0] sym.encoding #=> # f = λ{ 1 + 2 } f.call #=> 3 f = __send__('λ'.intern) { 1 + 2 } f.call #=> 3 # 文字エンコーディングのみが異なる f = __send__('λ'.force_encoding('EUC-JP').intern) { 1 + 2 } #=> undefined method `λ' for main:Object (NoMethodError) # バイト列と文字エンコーディングの両方が異なる場合 f = __send__('λ'.encode('EUC-JP').intern) { 1 + 2 } #=> undefined method `??' for main:Object (NoMethodError) === p.551最後のコードのコメント 誤 #=> undefined method `λ' for main:Object (NoMethodError) 正 #=> undefined method `??' for main:Object (NoMethodError) == レシピ226 === p.553 誤 a = "\000\001\002\003" a[2] #=> 2 a[2] = 5 正 a = "\000\001\002\003".force_encoding('ASCII-8BIT') a[2] #=> "\002" a[2] = "\005" == レシピ227 === p.555 実行例 誤 #=> 0 #=> 1 #=> ... #=> 10 正 #=> 0 #=> 1 #=> ... #=> 9