るりまサーチ

最速Rubyリファレンスマニュアル検索!
34件ヒット [1-34件を表示] (0.022秒)

別のキーワード

  1. _builtin each_object
  2. objectspace each_object
  3. object send
  4. object to_enum
  5. pp object_group

ライブラリ

キーワード

検索結果

Hash#shift -> [object, object] | nil (210.0)

ハッシュからキーが追加された順で先頭の要素をひとつ取り除き、 [key, value]という配列として返します。

...取り除かれた残りのハッシュに変更されます。

Ruby 3.2以前は、ハッシュが空の場合、デフォルト値(Hash#defaultまたはHash#default_procのブロックの値か、どちらもnilならばnil)
を返します(このとき、[key,value] という形式の値を...
..., "all"]
p h #=> {}
p h.shift #=> nil

h1 = Hash.new("default value")
p h1 #=> {}
p h1.shift #=> "default value"

h2 = Hash.new {|*arg| arg}
p h2 #=> {}
p h2.shift #=> [{}, nil]
//}


@see Array#shift...
...#=> [:cd, "all"]
p h #=> {}
p h.shift #=> nil

h1 = Hash.new("default value")
p h1 #=> {}
p h1.shift #=> nil

h2 = Hash.new {|*arg| arg}
p h2 #=> {}
p h2.shift #=> nil
//}


@see Array#shift...

Hash#dig(key, ...) -> object | nil (109.0)

self 以下のネストしたオブジェクトを dig メソッドで再帰的に参照して返し ます。途中のオブジェクトが nil であった場合は nil を返します。

...します。

@param key キーを任意個指定します。

//emlist[例][ruby]{
h = { foo: {bar: {baz: 1}}}

h.dig(:foo, :bar, :baz) # => 1
h.dig(:foo, :zot, :xyz) # => nil

g = { foo: [10, 11, 12] }
g.dig(:foo, 1) # => 11
//}

@see Array#dig, Struct#dig, OpenStruct#dig...

Hash#values_at(*keys) -> [object] (109.0)

引数で指定されたキーに対応する値の配列を返します。

...引数が指定されなかった場合は、空の配列を返します。

//emlist[例][ruby]{
h = {1=>"a", 2=>"b", 3=>"c"}

p h.values_at(1,3,4) #=> ["a", "c", nil]
# [h[1], h[3] ,h[4]] と同じ
//}

@see Hash#[] , Hash.new, Hash#default, Hash#default_proc, Array#values_at...