Bug in Ruby YAML interpreter?

R

Ralph Shnelvar

I have a YAML file that looks something like this:


en:
countries:
NI: "Nicaragua"
NL: "Netherlands"
NO: "Norway"
NP: "Nepal"
NR: "Nauru"
NU: "Niue"




When I run this through
------------------------------------

require 'yaml'

countries = []
countries_str = IO.read("lib\\locale\\en.yml"); nil
deserialized = YAML::load(countries_str); nil
puts "deserialized['en']['countries'].to_a.size=" + deserialized['en']['countries'].to_a.size.to_s
# puts deserialized['en']['countries'].to_a
deserialized['en']['countries'].each do |country|
# puts at_file_line_msg(__FILE__, __LINE__)
# puts country.class
p country[0]
p country[1]
countries << country[0]
end



country[0] comes up as false rather than as "NO".

Is this my weak understanding or is this a bug?
 
R

Ryan Davis

I have a YAML file that looks something like this:


en:
countries:
NI: "Nicaragua"
NL: "Netherlands"
NO: "Norway"
NP: "Nepal"
NR: "Nauru"
NU: "Niue"
...
country[0] comes up as false rather than as "NO".

Is this my weak understanding or is this a bug?

that's per spec... quote it to ensure the string NO.
 
J

Jörg W Mittag

Ralph said:
I have a YAML file that looks something like this:

en:
countries:
[...]
NO: "Norway"
[...]
country[0] comes up as false rather than as "NO".

Is this my weak understanding or is this a bug?

This is how Booleans are represented in YAML. An unescaped string
which is either "NO", "YES", "TRUE", "FALSE", "ON", "OFF", "Y" or "N"
(case-insensitive) is a Boolean value and not a string.

You need to escape the string:

"NO": "Norway"

BTW: If you hadn't put all those '; nil' there, you would have seen
the 'false => "Norway"' key in the hash printed out in IRB.

jwm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top