Is there some neat syntax in Ruby which would allow me to find the
people added in NEW who are not in OLD, and then find the people in OLD
who have need to be delete as they are not in NEW?
I was going to sort the arrays and iterate through them looking for
differences, but I suspect there is a really cool Ruby syntax to achieve
this.. what is it?
Thx
Graham
For set operations you'll probably want to use the "set" package. Part
of the stdlib.
See ruby-talk:65361 for potential gotchas wrt Array diff vs Set diff.
Regards,
Dan
---
require 'set'
OLD = Set.new(%w{ someone admin blah })
NEW = Set.new(%w{ admin blah newacct })
(OLD - NEW).each { |user|
# these users were removed...
}
(NEW - OLD).each { |user|
# and these have been added...
}
---
-Lennon
irb(main):005:0> %w(oldb newa newb) - %w(oldc oldb olda)
=> ["newa", "newb"]
irb(main):006:0> %w(oldc oldb olda) - %w(oldb newa newb)
=> ["oldc", "olda"]