🖥

Ruby - ハッシュの初期値を配列にする

2023/09/01に公開
example_hash = Hash.new{|hash, key| hash[key] = []}

ハッシュの要素にいきなり配列としてpush出来たりする

example_hash["foo"].push "bar"

example_hash # => {"foo"=>["bar"]}

参考

https://simanman.hatenablog.com/entry/2013/09/24/211044

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2022-08-02

Discussion