Because that's not how "each" works. You cannot call a method on "each"
in order to call it on every element. The "each" method without a block
returns an Enumerator.
So you'll either have to stick with the solution above or write your own
method. Or you should rethink the structure of your data. A deeply
nested hash or array is almost always bad design and should be replaced
with with an appropriate object (like a table, a tree or whatever fits
best).
module Enumerable
def recursive_each &block
(respond_to?(:each_value) ? each_value : each).each do |v|
if v.respond_to? :recursive_each
v.recursive_each(&block)
else
yield v
end
end
end
end