LoginSignup
27
12

More than 5 years have passed since last update.

Ruby で hash の配列から、特定の key の value のみの配列を作成する

Last updated at Posted at 2017-12-14

やりたいこと

hoge = [{a: 1, b: 2}, {a: 3, b: 4}]

から、

[1, 3]

を作る。

やり方

hoge.map { |h| h[:a] }

こんな簡単に実現できるとは思わなかった。。。情けない。

27
12
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
27
12