Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Last active December 21, 2015 16:19
Show Gist options
  • Save ashrithr/6332619 to your computer and use it in GitHub Desktop.
Save ashrithr/6332619 to your computer and use it in GitHub Desktop.
monkey patching
class String
def increment
s = ""
self.each_byte {|b| s << b.next.chr }
return s
end
end
# Usage: "ash".increment
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