Created
January 26, 2009 05:11
-
-
Save ujihisa/52714 to your computer and use it in GitHub Desktop.
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
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