Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created January 26, 2009 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ujihisa/52714 to your computer and use it in GitHub Desktop.
Save ujihisa/52714 to your computer and use it in GitHub Desktop.
module SelfStorage
# get :: IO [String]
def self.get
raise unless defined? DATA
DATA.readlines.map(&:chomp)
end
# append :: [String] -> IO ()
def self.append(ss)
raise unless defined? DATA
File.open(__FILE__, 'a') {|io|
io.puts ss
}
end
# rewrite :: [String] -> IO ()
def self.rewrite(ss)
raise unless defined? DATA
File.open(__FILE__, 'r+') {|io|
nil until io.gets.chomp == '__END__'
io.puts ss
io.truncate io.pos
}
end
end
#p SelfStorage.get
#SelfStorage.append(['1123', :ww])
#SelfStorage.rewrite(%w[jdsaf])
__END__
jdsaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment