Deserialize from yaml into array of objects

I have a yaml file which has many records like:

- !ruby/object:Employee
  first_name: John
  last_name: Gippert
  gender: male
  city: Detroit
  state: MI
  Programs:
  - !ruby/object:Program
    program_id: 3
    program_name: 401K
  -can be a varied number of programs for each employee

I need to parse this yaml file into an array of Employees.

I have a class variable which is an array. I would like to populate this
array with the employees, so I can use Array.Select to search for first
name, etc.

This code doesn't work and I am very new to Ruby. Have spent a lot of
time searching for this but cannot make it work. Please be specific and
provide details with your answers.

dep = Department.new
dep.employees= YAML::parse( File.read("university_db.yml"))
puts(db.employee.select{ |el| el.first_name == "john" }.length)

class Department

  attr_accessor :employees

  def initialize
    @employees= []
  end
end

···

--
Posted via http://www.ruby-forum.com/.

require 'yaml'
require 'pp'

class Employee
  attr_accessor :first_name, :last_name, :gender, :city, :state,
:Programs
end

class Program
  attr_accessor :program_id, :program_name
end

x = YAML.load_file('my_yaml.yml')
p x

--output:--
[#<Employee:0x00000100875fb8 @first_name="John", @last_name="Gippert",
@gender="male", @city="Detroit", @state="MI",
@Programs=[#<Program:0x00000100875018 @program_id=3,
@program_name="401K">, #<Program:0x00000100873e48 @program_id=2,
@program_name="LIBOR_fixing">]>, #<Employee:0x00000100873678
@first_name="Sally", @last_name="Gippert", @gender="female",
@city="Detroit", @state="MI", @Programs=[#<Program:0x000001008731f0
@program_id=3, @program_name="401K">]>]

PP.pp x

--output:--
[#<Employee:0x00000100875fb8
  @Programs=
   [#<Program:0x00000100875018 @program_id=3, @program_name="401K">,
    #<Program:0x00000100873e48 @program_id=2,
@program_name="LIBOR_fixing">],
  @city="Detroit",
  @first_name="John",
  @gender="male",
  @last_name="Gippert",
  @state="MI">,
#<Employee:0x00000100873678
  @Programs=[#<Program:0x000001008731f0 @program_id=3,
@program_name="401K">],
  @city="Detroit",
  @first_name="Sally",
  @gender="female",
  @last_name="Gippert",
  @state="MI">]

···

--
Posted via http://www.ruby-forum.com/.