class MemFs::Fake::File::Content

Attributes

pos[RW]

Public Class Methods

new(obj = '') click to toggle source
# File lib/memfs/fake/file/content.rb, line 12
def initialize(obj = '')
  @string = obj.to_s.dup
  @pos = 0

  __setobj__ @string
end

Public Instance Methods

close() click to toggle source
# File lib/memfs/fake/file/content.rb, line 9
def close
end
puts(*strings) click to toggle source
# File lib/memfs/fake/file/content.rb, line 19
def puts(*strings)
  strings.each do |str|
    @string << str
    next if str.end_with?($/)
    @string << $/
  end
end
read(length = nil, buffer = '') click to toggle source
# File lib/memfs/fake/file/content.rb, line 27
def read(length = nil, buffer = '')
  length ||= @string.length - @pos
  buffer.replace @string[@pos, length]
  @pos += buffer.bytesize
  buffer.empty? ? nil : buffer
end
to_s() click to toggle source
# File lib/memfs/fake/file/content.rb, line 38
def to_s
  @string
end
truncate(length) click to toggle source
# File lib/memfs/fake/file/content.rb, line 34
def truncate(length)
  @string.replace @string[0, length]
end
write(string) click to toggle source
# File lib/memfs/fake/file/content.rb, line 42
def write(string)
  text = string.to_s
  @string << text
  text.size
end