Last active
August 29, 2015 14:21
-
-
Save eddieantonio/e0ca7c36c4c75690fe67 to your computer and use it in GitHub Desktop.
Numeric#to_utf8 -> turns a number into the UTF-8 string of its codepoint.
This file contains 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
# Defines a method | |
module CoreExtensions | |
module CodepointToUTF8 | |
# Returns string of the number interpreted as a Unicode code point. | |
def to_utf8 | |
# http://ruby-doc.org/core-2.2.2/Array.html#pack-method | |
[self.truncate].pack("U") | |
end | |
# Installs the Monkey-Patch on Numeric. | |
def self.install | |
return if Numeric.method_defined? :to_utf8 | |
Numeric.include CoreExtensions::CodepointToUTF8 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment