fake_io.rb
1.0.0
{fakeio} هي وحدة Mixin لإنشاء فصول تشبه IO مزيفة.
$ gem install fake_io gem . add_dependency 'fake_io' , '~> 1.0' gem 'fake_io' , '~> 1.0' require 'fake_io'
class FakeFile
include FakeIO
def initialize ( chunks = [ ] )
@index = 0
@chunks = chunks
io_initialize
end
protected
def io_read
unless ( block = @chunks [ @index ] )
raise ( EOFError , "end of stream" )
end
@index += 1
return block
end
def io_write ( data )
@chunks [ @index ] = data
@index += 1
return data . length
end
end
file = FakeFile . new ( [ "one n two n " , "three n four" , " n " ] )
file . readlines
# => ["onen", "twon", "threen", "fourn"] راجع {file: license.txt} للحصول على التفاصيل.