Created
April 17, 2013 21:14
-
-
Save xpepper/5407821 to your computer and use it in GitHub Desktop.
charesc gem reloaded
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
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