Last active
December 21, 2015 16:19
-
-
Save ashrithr/6332619 to your computer and use it in GitHub Desktop.
monkey patching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def increment | |
s = "" | |
self.each_byte {|b| s << b.next.chr } | |
return s | |
end | |
end | |
# Usage: "ash".increment | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit class StringEnhancements(string: String) { | |
def increment = string.map(c => (c + 1).toChar) | |
} | |
//Usage: "ash".increment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment