Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.37 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. class String ### Open standard class String
  4.   def puts_uppercase ## Add a method
  5.     puts upcase
  6.   end
  7. end
  8.  
  9. "asdasd".puts_uppercase
  10.  
  11. class String
  12.   alias :old_puts_uppercase :puts_uppercase # save original puts_uppercase method
  13.  
  14.   def puts_uppercase # and override it
  15.     "HELLO #{self}".old_puts_uppercase
  16.   end
  17. end
  18.  
  19. "asdasdas".puts_uppercase
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement