use YAML::dump to convert your Person object array into YAML data : YAML « XML « Ruby






use YAML::dump to convert your Person object array into YAML data


# YAML::load turns YAML code into working Ruby objects

require 'yaml'

class Person
  attr_accessor :name, :age
end

yaml_string = <<END_OF_DATA
---
- !ruby/object:Person
  age: 45
  name: Jimmy
- !ruby/object:Person
  age: 23
  name: Laura Smith
END_OF_DATA

test_data = YAML::load(yaml_string)
puts test_data[0].name
puts test_data[1].name

 








Related examples in the same category

1.YAML Demo
2.Output a hash with yaml
3.Reading and Writing Configuration Files
4.Convert hash to configuration file
5.YAML for Marshaling