I am looking for a more elegant way to do this:
my_var = nil if my_var == 2
Currently I have to repeat my_var twice which doesn't read or look very nice.
This becomes even more ugly if I my_var is a key from a hash:
my_hash[:my_key] = nil if my_hash[:my_key] == 12
If I wanted to change it only if it was already nil then I could do this:
my_var ||= 2
Which is much cleaner.
Is there any nicer way of changing a variables value if it is equal to a certain value?