When I run ri Hash, the stringify_keys method shows up as an instance method in some of the listings where, each listing appears to be associated with a different gem or gem version.
But when I try calling it from the irb shell, it fails:
irb(main):035:0> h
=> {:this=>"this value", :that=>"that value"}
irb(main):031:0> h.instance_of? Hash
=> true
irb(main):032:0> h.stringify_keys
NoMethodError: undefined method `stringify_keys' for {:this=>"this value", :that=>"that value"}:Hash
from (irb):32
from /usr/local/bin/irb:12:in `<main>'
Also, when I run h.methods.sort in IRB, stringify_keys isn’t listed as a method.
Can someone explain this discrepancy? Is it a matter of my environment being outdated or just something I don’t understand about the Ruby documentation?
Rails (via ActiveSupport) monkey patches the
stringify_keysmethod intoHashso you won’t have it in a plainirbsession. You can load the core extensions by saying:See the Active Support Core Extensions Guide for details on loading individual monkey patches.