Class: MemFs::Fake::File::Content
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- MemFs::Fake::File::Content
- Defined in:
- lib/memfs/fake/file/content.rb
Instance Attribute Summary collapse
-
#pos ⇒ Object
Returns the value of attribute pos.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(obj = '') ⇒ Content
constructor
A new instance of Content.
- #puts(*strings) ⇒ Object
- #read(length = nil, buffer = +'')) ⇒ Object
- #to_s ⇒ Object
- #truncate(length) ⇒ Object
- #write(string) ⇒ Object
Constructor Details
#initialize(obj = '') ⇒ Content
Returns a new instance of Content.
13 14 15 16 17 18 19 20 |
# File 'lib/memfs/fake/file/content.rb', line 13 def initialize(obj = '') super @string = obj.to_s.dup @pos = 0 __setobj__ @string end |
Instance Attribute Details
#pos ⇒ Object
Returns the value of attribute pos.
9 10 11 |
# File 'lib/memfs/fake/file/content.rb', line 9 def pos @pos end |
Instance Method Details
#close ⇒ Object
11 |
# File 'lib/memfs/fake/file/content.rb', line 11 def close; end |
#puts(*strings) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/memfs/fake/file/content.rb', line 22 def puts(*strings) strings.each do |str| @string << str next if str.end_with?($/) @string << $/ end end |
#read(length = nil, buffer = +'')) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/memfs/fake/file/content.rb', line 30 def read(length = nil, buffer = +'') length ||= @string.length - @pos buffer.replace @string[@pos, length] @pos += buffer.bytesize buffer.empty? ? nil : buffer end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/memfs/fake/file/content.rb', line 41 def to_s @string end |
#truncate(length) ⇒ Object
37 38 39 |
# File 'lib/memfs/fake/file/content.rb', line 37 def truncate(length) @string.replace @string[0, length] end |
#write(string) ⇒ Object
45 46 47 48 49 |
# File 'lib/memfs/fake/file/content.rb', line 45 def write(string) text = string.to_s @string << text text.size end |