# Bug in Ruby YAML interpreter?

**URL:** <https://www.ruby-forum.com/t/bug-in-ruby-yaml-interpreter/183395>\
**Category:** Ruby\
**Created:** [February 12, 2010, 11:29pm UTC](https://www.ruby-forum.com/t/bug-in-ruby-yaml-interpreter/183395 "2010-02-12T23:29:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 12, 2010, 11:29pm UTC](https://www.ruby-forum.com/t/bug-in-ruby-yaml-interpreter/183395/1 "2010-02-12T23:29:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 12, 2010, 11:56pm UTC](https://www.ruby-forum.com/t/bug-in-ruby-yaml-interpreter/183395/2 "2010-02-12T23:56:46Z")

</div>

On Feb 12, 2010, at 14:29 , Ralph S. wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [February 13, 2010, 12:07am UTC](https://www.ruby-forum.com/t/bug-in-ruby-yaml-interpreter/183395/3 "2010-02-13T00:07:53Z")

</div>

Ralph S. 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
