Hello, can you please help me with this tricky problem:
Is there a way to force utf-8 encoding in to_yaml, ruby 1.9?
p "alex".to_yaml # "--- alex\n"
p "Алекс".to_yaml # "---
Maybe I missing something or don’t understand. I can’t get it, why we
should bother about encoding in todays?
Why there’s such a strange situation with encoding in ruby 1.9? It’s
impossible to set utf-8 as default (only via command-line command)? All
thouse tricky defaults and conversions …
According to TIOBE the Java user base, installation base and community
about 30 times more than Ruby. And it’s the universal language, You can
apply it generally almost to anything, and the only encoding that exist
there - it’s UTF. In 99.9% of cases You use UTF.
So, why the Ruby adds such a complexity? What’s the point, why you may
want ever to go with ANSI-8BIT?
prog.rb:2:in <main>': undefined methodto_yaml’ for “alex”:String
strange, but maybe there are the “require ‘yaml’” statement missing?
To encode all strings in your source file in UTF-8, put this line at the
top of your program:
Yes, I heard of this, You can also use this shortcut to do that:
export RUBYOPT="-Ku -rrubygems"
A round trip through yaml works for UTF-8 encoded strings in ruby 1.8.7.
In the program below, my original string contains a euro symbol, and
after a roundtrip through yaml, I get the same string back.
Sorry, I don’t understand it, You shown that the cryptic output of YAML
can be loaded back to normal object.
But in my situation it’s not enough, I need not ony load it back later
but it also should be readable in it’s marshalled form.
I need to modify thouse *.yaml configs by hand, so those cryptic stuff
like “\xE2\x82\xAC” in *.yaml files is unacceptable.