Skip to content

Instantly share code, notes, and snippets.

Created January 30, 2013 05:31
Show Gist options
  • Save anonymous/2221f78f99ce7c324d27 to your computer and use it in GitHub Desktop.
Save anonymous/2221f78f99ce7c324d27 to your computer and use it in GitHub Desktop.
Create, Read or Append data to a file...
def handle_file(filename,data=nil)
if File.exist?(filename)
if not data.nil?
return Marshal.load(File.read(filename)).push(data)
else
return Marshal.load(File.read(filename))
end
else
data ||= []
File.open(filename,'w') do |fle|
fle.write(Marshal.dump(data))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment