7
7

More than 5 years have passed since last update.

inject の代わりに each_with_object を使う

Posted at

メモ。Ruby 1.9 なら標準で、1.8.7 環境なら active_support で。

require 'active_support/core_ext/enumerable'

で。

{:foo => '1', :bar => '2'}.each_with_object({}) {|(key, value), object|
  object[key] = value.to_i
}
# => {:foo=>1, :bar=>2}
7
7
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
7
7