# YAML iteration

**URL:** <https://www.ruby-forum.com/t/yaml-iteration/130502>\
**Category:** Ruby\
**Created:** [February 28, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/yaml-iteration/130502 "2008-02-28T20:25:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 28, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/yaml-iteration/130502/1 "2008-02-28T20:25:34Z")

</div>

Hi,

This is the YAML

test: tiscali1  
url: [http://tiscali3-test.vizumi.com/](http://tiscali3-test.vizumi.com/)  
first\_name: aidy  
surname: smith  
email: ‘removed\_email\_address@domain.invalid’  
password: password  
registration: KJHDF123

test: tiscali2  
url: [http://tiscali3-test.vizumi.com/](http://tiscali3-test.vizumi.com/)  
first\_name: aidy  
surname: smith222  
email: ‘removed\_email\_address@domain.invalid’  
password: password  
registration: KJHDF122

This is the code that is reading it:

`
def SmokeTest.create_from_yaml_file(filename)
  data = YAML.load_file(filename)
  obj = new(data['test'], data['url'])
  obj.register(data['first_name'], data['surname'], data['email'],
               data['password'], data['registration'])
  obj
end
`

`tiscali = SmokeTest.create_from_yaml_file(‘C:\test.yaml’)
`

I would like to read the first YAML hash first, then the second and  
any more, If the hash’s are commneted out, i would like the data and  
test to be ignored.

Aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [February 28, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/yaml-iteration/130502/2 "2008-02-28T21:45:50Z")

</div>

aidy wrote:

> Hi,

\> I would like to read the first YAML hash first, then the second and \> any more, If the hash's are commneted out, i would like the data and \> test to be ignored. \> \> Aidy \> 

I believe you want YAML.load\_documents:  
[http://ruby-doc.org/stdlib/libdoc/yaml/rdoc/classes/YAML.html#M010373](http://ruby-doc.org/stdlib/libdoc/yaml/rdoc/classes/YAML.html#M010373)  
Not sure how comments work in YAML though.

-Justin
