fork download
  1. #!/usr/bin/env ruby
  2.  
  3. class X
  4. def initialize(var)
  5. @attribute = var
  6. end
  7.  
  8. def attribute
  9. @attribute
  10. end
  11. end
  12.  
  13. x = [X.new(1), X.new(2), X.new(3)]
  14. y = [X.new(1), X.new(2), X.new(4)]
  15.  
  16. not_in_y = x.reject{ |x_item| y.index { |y_item| x_item.attribute == y_item.attribute } }
  17. not_in_x = y.reject{ |y_item| x.index { |x_item| x_item.attribute == y_item.attribute } }
  18.  
  19. p not_in_y
  20. p not_in_x
Success #stdin #stdout 0.01s 7460KB
stdin
Standard input is empty
stdout
[#<X:0x9d74070 @attribute=3>]
[#<X:0x9d74020 @attribute=4>]