0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

each_value

Posted at

引数なしだとEnumeratorを返し、ブロックだと自信を返す

each_value {|value| ... } -> self[permalink][rdoc][edit]
each_value -> Enumerator
ハッシュの値を引数としてブロックを評価します。

反復の際の評価順序はキーが追加された順です。ブロック付きの場合selfを、無しで呼ばれた場合 Enumerator を返します。

irb(main):002> {:a=>1, :b=>2}.each_value {|v| p v}
1
2
=> {:a=>1, :b=>2}
irb(main):004> p({:a=>1, :b=>2}.each_value)
#<Enumerator: {:a=>1, :b=>2}:each_value>
=> #<Enumerator: ...>

irb(main):005> p({:a=>1, :b=>2}.each_value.class)
Enumerator
=> Enumerator

irb(main):006> a = {:a=>1, :b=>2}.each_value {|v| p v}
1
2
=> {:a=>1, :b=>2}
irb(main):007> a.class
=> Hash

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?