开发者

Ruby - NoMethodError: undefined method `reverse_merge'

开发者 https://www.devze.com 2023-04-05 21:08 出处:网络
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})
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消