I discovered this interesting nugget of oddity today. While normal Ruby arrays are ‘comma separated” and space agnostic ie.
>> array = [2,3 ,4, 5]
=> [2, 3, 4, 5]
>> array.size
=> 4
>> array_spaces = [2 , 3 , 4 , 5]
=> [2, 3, 4, 5]
>> array_spaces.size
=> 4
In case of YAML, the spaces between array elements makes a difference. A much needed code snippet :
A file ‘myfile.yml’
array: [ 1 , 2 ,3, 4]
array_spaces: [1 , 2 , 3 , 4]
Loading this file in ‘irb’:
>> f =YAML.load_file('myfile.yml')
=> {"array"=>[1, "2 ,3", 4], "array_spaces"=>[1, 2, 3, 4]}
>> f["array"]
=> [1, "2 ,3", 4]
>> f["array"].size
=> 3
>> f["array_spaces"]
=> [1, 2, 3, 4]
>> f["array_spaces"].size
=> 4
Now that’s not Ruby-ish. But then, as a seasoned co-developer pointed out, YAML should be language agnostic. I still find it a bit odd, though. Hmmm, interesting. Point taken.
Great text and nice blog.
Keep posting stuff like this i really like it
Genial fill someone in on and this mail helped me alot in my college assignement. Thanks you as your information.
Can I link this post from my blog? Hunter
Interesting information, thanks that you wrote – I look forward to more.
Sure.
Thanks for the tip!
I am going to add your blog to my list!