Skip to content

Instantly share code, notes, and snippets.

@yancya
Created November 12, 2013 02:53
Show Gist options
  • Save yancya/7424696 to your computer and use it in GitHub Desktop.
Save yancya/7424696 to your computer and use it in GitHub Desktop.
ハッシュの配列の各要素の共通のキーの値の配列に簡単にアクセスするにはどうしたらいいか
def method_missing(name)
Proc.new{|o| o[name]}
end
hoges = [{hoge: 1, fuga: 2}, {hoge: 3, fuga: 4}]
p hoges.map(&fuga) #=> [2, 4]
p hoges.map(&hoge).reduce(&:+) #=> 4
@yancya
Copy link
Author

yancya commented Nov 12, 2013

許されない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment