Reading and Writing YAML files in Ruby

Ruby makes it simple to read and write YAML files.

require 'yaml'

def yaml_save object, filename
  File.open filename, 'w' do |f|
    f.write(object.to_yaml)
  end
end

def yaml_load filename
  yaml_string = File.read filename

  YAML::load yaml_string
end

test_array = ['Slick Shoes',
              'Bully Blinders',
              'Pinchers of Peril']

filename = 'DatasGadgets.txt'

# save the file
yaml_save test_array, filename

# load the file
read_array = yaml_load filename

puts(read_array == test_array)