require 'yaml'

class Serialization
  def initialize
    
  end
  
  def serialize(filename,data)
    File.open(filename,"w") do |i|
      #w means writable
      i.write(data.to_yaml)
      i.close
    end
  end

  def serialize_to_array(filename,data)
    if File.exists?(filename)
        array = deserialize(filename)
        array.push(data)
        serialize(filename, array)
      else
        array = [data]
        serialize(filename, array)
      end
  end
  
  def deserialize(filename)
    data = YAML::load_file(filename)
    return data
  end
  
  def deserialize_last_value_in_array(filename)
    data = YAML::load_file(filename)
    return data.last
  end
  
  def deserialize_biggest_value_in_array(filename)
    data = YAML::load_file(filename)
    max = 0
    data.each {|itm| max = itm if itm > max}
    return max
  end
  
end

