ruby-reference-manual:499
From: sheepman <sheepman@s...>
Date: Sun, 14 Oct 2007 21:09:36 +0900
Subject: [ruby-reference-manual:499] Hash#== などのエントリー
こんばんは sheepman です。
Hash#==, Hash#eql?, Hash#hash のエントリーを書いてみました。
よろしくお願いします。
--- ==(other) -> bool
--- ===(other) -> bool
#@since 1.9.0
--- eql?(other) -> bool
#@end
自身と other が同じ数のキーを保持し、キーが eql? メソッドで比較して全て等しく、
値が == メソッドで比較して全て等しい場合に true を返します。
そうでない場合に false を返します。
@param other 自身と比較したい Hash オブジェクトを指定します。
{ 1 => :a } == { 1 => :a } #=> true
{ 1 => :a } == { 1 => :a , 2 => :b } #=> false
{ 1 => :a } == { 1.0 => :a } #=> false ( 1.eql?(1.0) は false なので)
{ :x => 1 } == { :x => 1.0 } #=> true ( 1 == 1.0 は true なので)
#@if(version < "1.9.0")
--- eql?(other) -> bool
#@end
--- equal?(other) -> bool
指定された other が self である場合のみ true を返します。
そうでない場合に false を返します。
@param other 自身と比較したい Hash オブジェクトを指定します。
#@if(version < "1.9.0")
{}.eql?({}) #=> false
a = {}
a.eql?(a) #=> true
#@else
{}.equal?({}) #=> false
a = {}
a.equal?(a) #=> true
#@end
--- hash -> Integer
#@since 1.9.0
自身が保持するキーと値のハッシュ値を元にして算出した整数を返します。
自身が保持するキーや値が変化すればこのメソッドが返す値も変化します。
a = {}
a.hash #=> 0
a[1] = :x
a.hash #=> 329543
#@else
自身の [[m:Object#object_id]] を返します。これは [[c:Object]] クラスで定義されたデフォルトの動作です。
メソッド hash の返り値は自身が保持するキーや値に影響されません。
a = {}
a.hash #=> 538688380
a[1] = :a
a.hash #=> 538688380
#@end
--
sheepman / TAMURA Takashi
sheepman@s...
--
ML: ruby-reference-manual@m...
使い方: http://QuickML.com/