Here you save yaml objects as Person objects, and then when you load them back, they will be loaded into Person objects, which simplifies their handling.
The first change will change your yaml file to something like this:
--- - !ruby/object:Person name: John Doe sname: jdoe email: jdoe@gmail.com - !ruby/object:Person name: Jane Doe sname: jdoe email: jane@hotmail.com
Now you can load your yaml file into an array of Person objects, and then manipulate the array:
FILENAME = 'data.yaml' class Person attr_accessor :name, :sname, :email end require "yaml"
source share