Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method diff the active/support ruby not working

I need help with this method I am following the curse ruby bits de codeschool it adds a library called active_support to ruby but this method not working for me I think that this function is decrapited I am not sure

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>'
like image 449
user3623442 Avatar asked May 15 '26 02:05

user3623442


1 Answers

The Rails team deprecated Hash#diff in ActiveSupport in favor of MiniTest#diff. See https://github.com/rails/rails/pull/8142.

They tend to deprecate things often (another reason why testing is so important).

like image 82
InChargeOfIT Avatar answered May 16 '26 15:05

InChargeOfIT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!