Skip to content

Instantly share code, notes, and snippets.

@xpepper
Created April 17, 2013 21:14
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 xpepper/5407821 to your computer and use it in GitHub Desktop.
Save xpepper/5407821 to your computer and use it in GitHub Desktop.
charesc gem reloaded
class Module
m = instance_method(:const_missing)
define_method :const_missing do |name|
if name.to_s =~ /^U([0-9a-fA-F]{4})$/
[$1.to_i(16)].pack("U*")
else
m.bind(self).call(name)
end
end
end
puts U0123 # => ģ
puts U0041 # => A
puts Fred # => raise NameError: uninitialized constant Fred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment