Joel VanderWerf
11/1/2006 8:34:00 PM
Daniel Berger wrote:
> Hi all,
>
> Ruby 1.8.5
>
> irb(main):002:0> Set[1,2,3] ^ Set[3,4,5,5]
> => #<Set: {5, 1, 2, 4}>
>
> Ok, looks good.
>
> irb(main):003:0> Set[1,2,3] ^ [3,4,5,5]
> => #<Set: {1, 2, 4}>
>
> What?! I'm confused. Do I need a refresher in Set theory or something?
I think I can guess why it is happening:
irb(main):009:0> (0..10).each {|n| p Set[1,2,3] ^ ([3,4]+[5]*n)}
#<Set: {1, 2, 4}>
#<Set: {5, 1, 2, 4}>
#<Set: {1, 2, 4}>
#<Set: {5, 1, 2, 4}>
#<Set: {1, 2, 4}>
#<Set: {5, 1, 2, 4}>
#<Set: {1, 2, 4}>
#<Set: {5, 1, 2, 4}>
#<Set: {1, 2, 4}>
#<Set: {5, 1, 2, 4}>
#<Set: {1, 2, 4}>
=> 0..10
Looks like the array argument is used to flip-flop the elements of the set.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407