I'm not a Ruby dev by trade, but am using Capistrano for PHP deployments. I'm trying to cleanup the output of my script and am trying to add a unicode check mark as discussed in this blog.
The problem is if I do:
checkmark = "\u2713"
puts checkmark
It outputs "\u2713" instead of ✓
I've googled around and I just can't find anywhere that discusses this.
TLDR: How do I puts
or print
the unicode checkmark U-2713?
EDIT
I am running Ruby 1.8.7 on my Mac (OSX Lion) so cannot use the encode
method. My shell is Bash in iTerm2.
In Ruby 1.9.x+
Use
String#encode
:prints
In Ruby 1.8.7
In newer versions of Ruby, you don't need to enforce encoding. Here is an example with
2.1.2
:Just make sure you use double quotes!
Same goes as above in ERB, no forced encoding required, works perfectly, tested at Ruby 2.3.0
Much appreciation
falsetru's answer is incorrect.
This transcodes the checkmark from the current system encoding to UTF-8 encoding. (That works only on a system whose default is already UTF-8.)
The correct answer is:
This modifies the string's encoding, without modifying any character sequence.