Hello Rubyists, I am a bit stumped here. I want to extend the 'load_file' method in the YAML module. Following along with the PickAxe example of making old methods do new things, I try this in irb:
module YAML alias_method :orig_load_f, :load_file def load_file(*args) contents = orig_load_f(*args) contents.symbolize_keys.each_value {|v| v.symbolize_keys } end end
But after that last 'end', irb explodes, saying:
NameError: undefined method `load_file' for module `YAML' from (irb):2:in `alias_method' from (irb):2
But, continuing in irb:
#But apparently that NameError is not true?
?> YAML.load_file('test.yml') => {"node_three"=>{"a"=>1, "b"=>2, "c"=>3}, "node_one"=>{"a"=>1, "b"=>2, "c"=>3} , "node_two"=>{"a"=>1, "b"=>2, "c"=>3}}
Am I missing something or taking the wrong approach? Any input would be much appreciated.
Thanks, kodama