Reputation: 32130
if given the following
a = [1,2,3]
b = [3,4,5]
a&b #=> [3]
b - a&b #=> [4,5]
b - a #=> [4,5]
why does this work
[1,2,3] - [3] #=> [1,2]
but not this
a - a&b #=> [] ??
Upvotes: 2
Views: 50
Reputation: 8821
2.1.2 :006 > a - a&b
=> []
2.1.2 :007 > a - (a&b)
=> [1, 2]
You can get ruby operator precedence table from here.
Upvotes: 2
Reputation: 51151
Because -
has higher precedence here than &
:
a - (a&b)
# => [1, 2]
Upvotes: 5