YAML や JSON で表現されるような、スカラー値、Array、Hash で構成されたオブジェクトについて、再帰的に処理をする際、下記のようなイディオムが使える。 def foo(obj) case obj when Array obj.map{|e| foo(e)} # Array の要素を再帰的に処理 when Hash obj.inject({}) do |hash, (k, v)| hash[k] = foo(v) # Hash の値を再帰的に処理 hash end else obj end end def stringify_keys(obj) case obj when Array obj.map{|e| stringify_keys(e)} when Hash obj.inject({}) do |hash, (k, v)| # ここが変わる hash[k.to_s] =