方法diff活动/支持ruby不工作

时间:2014-09-16 23:19:50

标签: ruby-on-rails ruby ruby-on-rails-3

我需要这方法的帮助 我跟随诅咒ruby bits de codeschool 它为ruby添加了一个名为active_support的库 但这种方法对我不起作用 我认为这个函数是decrapited 我不确定

require 'active_support/all'
 {1 => 2}.diff(1 => 2)         # => {}
  {1 => 2}.diff(1 => 3)         # => {1 => 2}
  {}.diff(1 => 2)               # => {1 => 2}
  {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}

fernando@fernando:~/ruby$ ruby tweets.rb 
tweets.rb:2:in `<main>': undefined method `diff' for {1=>2}:Hash (NoMethodError)
fernando@fernando:~/ruby$ irb
irb(main):001:0> require 'active_support/all'
=> true
irb(main):002:0>  {1 => 2}.diff(1 => 2)         # => {}
NoMethodError: undefined method `diff' for {1=>2}:Hash
    from (irb):2
    from /usr/bin/irb:12:in `<main>'
irb(main):003:0>   {1 => 2}.diff(1 => 3)         # => {1 => 2}
NoMethodError: undefined method `diff' for {1=>2}:Hash
    from (irb):3
    from /usr/bin/irb:12:in `<main>'
irb(main):004:0>   {}.diff(1 => 2)               # => {1 => 2}
NoMethodError: undefined method `diff' for {}:Hash
    from (irb):4
    from /usr/bin/irb:12:in `<main>'
irb(main):005:0>   {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
NoMethodError: undefined method `diff' for {1=>2, 3=>4}:Hash
    from (irb):5
    from /usr/bin/irb:12:in `<main>'

1 个答案:

答案 0 :(得分:4)

Rails团队在ActiveSupport中弃用了Hash#diff,转而使用MiniTest #diff。请参阅https://github.com/rails/rails/pull/8142

他们倾向于经常弃用事物(测试如此重要的另一个原因)。