Module: CRFPP::Filelike

Included in:
Data, Model, Template
Defined in:
lib/crfpp/filelike.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject



7
8
9
# File 'lib/crfpp/filelike.rb', line 7

def path
  @path ||= Tempfile.new('filelike').path
end

Instance Method Details

#readObject



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