I want a placeholder for a single character string that I haven't implemented yet. How do I print a snowman in Ruby 1.9?
Currently, I can do
# coding: utf-8
puts "☃"
or
puts "\u2603"
but is it possible to use the "Index entries" field (mentioned here) snowy weather
or SNOWMAN
or weather, snowy
to get the character to print?
I am not using Rails.
You may download the Name Index from unicode.org and parse the characters names into a Hash (or better a DB or similiar).
Then you can get it with normal data access functions.
Example:
# coding: utf-8
index = {}
File.readlines('Index.txt').each{|line|
line =~ /(.*)\t(.*)$/
index[$1] = $2.to_i(16).chr("UTF-8")
}
snowman = index['SNOWMAN']
p snowman #hope it works. My shell does not show the snowman
p "\u2603" == snowman #true
Edit:
There is a gem unicode_utils. With this gem you can use:
require "unicode_utils/grep"
p UnicodeUtils.grep(/^snowman$/) #=> [#<U+2603 "\u2603" SNOWMAN utf8:e2,98,83>]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With