Bug in Ruby YAML interpreter?

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?

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

···

On Feb 12, 2010, at 14:29 , Ralph Shnelvar wrote:

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?

Ralph Shnelvar wrote:

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