summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-02-14 19:54:27 +0100
committerPatrick Simianer <p@simianer.de>2014-02-14 19:54:27 +0100
commitbb57cda77b3e263fd30dab17c4bd42f1dfadd856 (patch)
tree77dd412e70fd7f59c350b14e31652167b0b5b79f
parent062eda911830c779aa685885b8e15ecceabfc085 (diff)
class methods for Read/WriteFile
-rw-r--r--lib/nlp_ruby/fileutil.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/nlp_ruby/fileutil.rb b/lib/nlp_ruby/fileutil.rb
index e560aae..eb69136 100644
--- a/lib/nlp_ruby/fileutil.rb
+++ b/lib/nlp_ruby/fileutil.rb
@@ -23,14 +23,35 @@ class ReadFile
@f.readlines
end
+ def self.readlines fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.readlines
+ f.close
+ return r
+ end
+
def readlines_strip
self.readlines.map{ |i| i.strip }
end
+ def self.readlines_strip fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.readlines_strip
+ f.close
+ return r
+ end
+
def read
@f.read
end
+ def self.read fn, encoding='utf-8'
+ f = ReadFile.new fn, encoding
+ r = f.read
+ f.close
+ return r
+ end
+
def close
@f.close if @f!=STDIN
end
@@ -54,6 +75,12 @@ class WriteFile
@f.write s
end
+ def self.write s, fn, encoding='utf-8'
+ f = WriteFile.new fn, encoding
+ f.write s
+ f.close
+ end
+
def close
@f.close if @f!=STDIN
end