Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Created May 19, 2015 00:18
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/3e3c1c2ca22629299d71 to your computer and use it in GitHub Desktop.
Save eddieantonio/3e3c1c2ca22629299d71 to your computer and use it in GitHub Desktop.
module U
def self.+(obj)
codepoint = obj.is_a?(Numeric) ? obj.truncate : obj.to_s.hex
to_utf8 codepoint
end
# Returns a UTF-8 encoded string of the Integer interpreted as a Unicode
# code point.
def self.to_utf8(integer)
# See: http://ruby-doc.org/core-2.2.2/Array.html#pack-method
[integer].pack("U")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment