fork download
  1. $VERBOSE = true
  2.  
  3. valid_table = [
  4. [1,"eric", 23, "seattle"],
  5. [1,"eric", 23, "chicago"]
  6. ]
  7.  
  8. invalid_table = [
  9. [1,"eric", 23, "seattle"],
  10. [2,"eric", 45, "seattle"]
  11. ]
  12.  
  13. puts '# uniq'
  14. p valid_table.uniq
  15. p valid_table.uniq{|l|[l[1], l[3]]}
  16. p valid_table.uniq!{|l|[l[1], l[3]]}
  17. p valid_table
  18. p valid_table.uniq!{|l|[l[1], l[3]]}
  19. p valid_table
  20.  
  21. puts '# uniq!'
  22. p invalid_table.uniq
  23. p invalid_table.uniq{|l|[l[1], l[3]]}
  24. p invalid_table.uniq!{|l|[l[1], l[3]]}
  25. p invalid_table
  26. p invalid_table.uniq!{|l|[l[1], l[3]]}
  27. p invalid_table
Success #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
# uniq
[[1, "eric", 23, "seattle"], [1, "eric", 23, "chicago"]]
[[1, "eric", 23, "seattle"], [1, "eric", 23, "chicago"]]
nil
[[1, "eric", 23, "seattle"], [1, "eric", 23, "chicago"]]
nil
[[1, "eric", 23, "seattle"], [1, "eric", 23, "chicago"]]
# uniq!
[[1, "eric", 23, "seattle"], [2, "eric", 45, "seattle"]]
[[1, "eric", 23, "seattle"]]
[[1, "eric", 23, "seattle"]]
[[1, "eric", 23, "seattle"]]
nil
[[1, "eric", 23, "seattle"]]