-
-
Save anonymous/2221f78f99ce7c324d27 to your computer and use it in GitHub Desktop.
Create, Read or Append data to a file...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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