Is it undocumented, or is some magic going on behind the scenes -- such as the hash getting converted to an array?
The Hash class includes the Enumerable module, which defines #collect in terms of #each. In this case, Hash#each yields key,value pairs, so #collect does too. It doesn't get converted to an array before map is called. It does get converted to an array through the normal behavior of #map:
You might find something like the following exploratory utility useful:
def method_report(klass)
result = klass.ancestors.inject(Array.new) do |result, anc|
ms = (anc.instance_methods + anc.methods).sort.uniq
result.last[1] -= ms if result.last
result << [anc.name, ms]
end
result.each do |k, v|
puts "----", k
v.each {|m| puts "\s\s#{m}"}
end
end
# and here's how to use it
method_report(Hash)
I'm sure there are much snazzier versions out there. m.