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 |
# File 'lib/memfs/fake/file/content.rb', line 13 def initialize(obj = '') @string = obj.to_s.dup @pos = 0 __setobj__ @string end |
Instance Attribute Details
#pos ⇒ Object
Returns the value of attribute pos.
8 9 10 |
# File 'lib/memfs/fake/file/content.rb', line 8 def pos @pos end |
Instance Method Details
#close ⇒ Object
10 11 |
# File 'lib/memfs/fake/file/content.rb', line 10 def close end |
#puts(*strings) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/memfs/fake/file/content.rb', line 20 def puts(*strings) strings.each do |str| @string << str @string << $/ unless str.end_with?($/) end end |
#read(length = nil, buffer = '') ⇒ Object
27 28 29 30 31 32 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/memfs/fake/file/content.rb', line 38 def to_s @string end |
#truncate(length) ⇒ Object
34 35 36 |
# File 'lib/memfs/fake/file/content.rb', line 34 def truncate(length) @string.replace @string[0, length] end |
#write(string) ⇒ Object
42 43 44 45 46 |
# File 'lib/memfs/fake/file/content.rb', line 42 def write(string) text = string.to_s @string << text text.size end |