Module: CRFPP::Filelike
Instance Attribute Summary collapse
Instance Method Summary collapse
- #read ⇒ Object
- #write(file = path, content = to_s) ⇒ Object (also: #save)
Instance Attribute Details
#path ⇒ Object
7 8 9 |
# File 'lib/crfpp/filelike.rb', line 7 def path @path ||= Tempfile.new('filelike').path end |
Instance Method Details
#read ⇒ Object
21 22 23 24 25 26 |
# File 'lib/crfpp/filelike.rb', line 21 def read f = File.open(path, 'r:UTF-8') f.read ensure f.close end |
#write(file = path, content = to_s) ⇒ Object Also known as: save
11 12 13 14 15 16 17 |
# File 'lib/crfpp/filelike.rb', line 11 def write(file = path, content = to_s) File.open(file, 'w:UTF-8') do |f| f.write(content) f.close end self end |