Reputation: 1015
Can Anyone point Me in the direction of how to tell when, for example, the + operator is used in ruby as opposed to the += operator from the inside of the + operator's definition? To illustrate:
class A
def +(b)
if is_theCallActuallyACompoundAssignment?
compoundAssignment = true
else
compoundAssignment = false
end
doOtherStuff
end
end
Is there a Kernel method, perhaps?
Upvotes: 1
Views: 84
Reputation: 17960
This code:
a += 5
Gets translated to this:
a = a + 5
Your +
method will not know that you received a compound assignment.
Upvotes: 5