Class: TempIO

Inherits:
Object show all
Defined in:
lib/rubygems/test_utilities.rb

Overview

A StringIO duck-typed class that uses Tempfile instead of String as the backing store. -- This class was added to flush out problems in Rubinius' IO implementation.

Constant Summary

@@count =
0

Instance Method Summary (collapse)

Constructor Details

- (TempIO) initialize(string = '')

A new instance of TempIO



138
139
140
141
142
143
# File 'lib/rubygems/test_utilities.rb', line 138

def initialize(string = '')
  @tempfile = Tempfile.new "TempIO-#{@@count += 1}"
  @tempfile.binmode
  @tempfile.write string
  @tempfile.rewind
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(meth, *args, &block)



145
146
147
# File 'lib/rubygems/test_utilities.rb', line 145

def method_missing(meth, *args, &block)
  @tempfile.send(meth, *args, &block)
end

Instance Method Details

- (Boolean) respond_to?(meth)

Returns:

  • (Boolean)


149
150
151
# File 'lib/rubygems/test_utilities.rb', line 149

def respond_to?(meth)
  @tempfile.respond_to? meth
end

- (Object) string



153
154
155
156
157
# File 'lib/rubygems/test_utilities.rb', line 153

def string
  @tempfile.flush

  Gem.read_binary @tempfile.path
end