Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Unary Operators for Non-Numeric Objects
- It's possible to implement unary operators to an object by defining the `-@` and `+@` methods within the class declaration
- ```ruby
- class True
- def -@
- false
- end
- def +@
- true
- end
- end
- t = True.new
- p -t
- p +t
- ```
- produces
- ```ruby
- false
- true
- ```
Add Comment
Please, Sign In to add comment