Guest User

Untitled

a guest
Apr 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. # Unary Operators for Non-Numeric Objects
  2.  
  3. It's possible to implement unary operators to an object by defining the `-@` and `+@` methods within the class declaration
  4.  
  5. ```ruby
  6. class True
  7. def -@
  8. false
  9. end
  10.  
  11. def +@
  12. true
  13. end
  14. end
  15.  
  16. t = True.new
  17.  
  18. p -t
  19. p +t
  20. ```
  21.  
  22. produces
  23.  
  24. ```ruby
  25. false
  26. true
  27. ```
Add Comment
Please, Sign In to add comment