From bb57cda77b3e263fd30dab17c4bd42f1dfadd856 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Fri, 14 Feb 2014 19:54:27 +0100 Subject: class methods for Read/WriteFile --- lib/nlp_ruby/fileutil.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/nlp_ruby') 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 -- cgit v1.2.3