Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddieantonio/e0ca7c36c4c75690fe67 to your computer and use it in GitHub Desktop.
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.
# 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