How can I get the opposite of a boolean in Ruby (I know that it is converted to 0/1) using a method inline?
say I have the given instance:
class Vote
def return_opposite
self.value
end
end
Which obviously doesn't do anything, but I can't seem to find a method that is simple and short something like opposite()
or the like. Does something like this exist and I'm just not looking at the right place in the docs? If one doesn't exist is there a really short ternary that would toggle it from 1 => 0 or 0 => 1?
I like to use this
@object.boolean = [email protected]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With