Ruby - NoMethodError: undefined method `reverse_merge'
ruby-1.9.2-p180 :007 > a = {:a => 10, :b => 20}
=> {:a=>10, :b=>20}
ruby-1.9.2-p180 :008 > a.reverse_merge({:c => 30})
NoMethodErro开发者_如何学Gor: undefined method `reverse_merge' for {:a=>10, :b=>20}:Hash
from (irb):8
from /home/sayuj/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
How to fix this NoMethodError
?
require 'active_support/core_ext'
source: http://api.rubyonrails.org/v2.3.8/classes/ActiveSupport/CoreExtensions/Hash/ReverseMerge.html
reverse_merge
is a Rails method, not a Ruby method. Use plain old merge
.
精彩评论