Skip to content

Instantly share code, notes, and snippets.

@kasima
Created March 2, 2011 00:48
Show Gist options
  • Save kasima/850230 to your computer and use it in GitHub Desktop.
Save kasima/850230 to your computer and use it in GitHub Desktop.
Generate unicode escape strings
def escaped_unicode(s)
s.unpack("U*").map do |v|
if v == 10
'\n'
elsif v < 256
v.chr
else
'\u{'+v.to_s(16)+'}'
end
end.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment