Guest User

Untitled

a guest
Feb 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. module Unicode
  2. def self.const_missing(name)
  3. # Check that the constant name is of the right form: U0000 to U10FFFF
  4. if name.to_s =~ /^U([0-9a-fA-F]{4,5}|10[0-9a-fA-F]{4})$/
  5. # Convert the codepoint to an immutable UTF-8 string,
  6. # define a real constant for that value and return the value
  7. #p name, name.class
  8. const_set(name, [$1.to_i(16)].pack("U").freeze)
  9. else # Raise an error for constants that are not Unicode.
  10. raise NameError, "Uninitialized constant: Unicode::#{name}"
  11. end
  12. end
  13. end
Add Comment
Please, Sign In to add comment