るりまサーチ

最速Rubyリファレンスマニュアル検索!
22件ヒット [1-22件を表示] (0.054秒)
トップページ > クラス:Hash[x] > クエリ:_builtin[x] > クエリ:hash[x] > クエリ:===[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

検索結果

Hash#===(other) -> bool (32113.0)

自身と other が同じ数のキーを保持し、キーが eql? メソッドで比較して全て等しく、 値が == メソッドで比較して全て等しい場合に真を返します。

...して全て等しく、
値が == メソッドで比較して全て等しい場合に真を返します。

@param other 自身と比較したい Hash オブジェクトを指定します。

//emlist[例][ruby]{
#(出力関数は省略)
{ 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 なので)
//}

@see Hash#equal?...

Hash#invert -> Hash (17132.0)

値からキーへのハッシュを作成して返します。

...0=>"b", 200=>"c", 300=>"e"}
//}

===
参考
値が重複していたときに備えて、変換後の値を配列として保持するには、次のようにします。

//emlist[][ruby]{
def safe_invert(orig_hash)
orig_hash.each_key.group_by do |key|
orig_hash[key]
end
end
p safe_invert({...
..."a"=>1, "b"=>1, "c"=>3}) # => {1=>["a", "b"], 3=>["c"]}
//}

@see Hash#key...