Class: IOStub
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ IOStub
Returns a new instance of IOStub.
4
5
6
7
|
# File 'lib/mspec/helpers/io.rb', line 4
def initialize
@buffer = []
@output = ''
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
22
23
24
|
# File 'lib/mspec/helpers/io.rb', line 22
def method_missing(name, *args, &block)
to_s.send(name, *args, &block)
end
|
Instance Method Details
13
14
15
16
|
# File 'lib/mspec/helpers/io.rb', line 13
def << str
@buffer << str
self
end
|
#==(other) ⇒ Object
26
27
28
|
# File 'lib/mspec/helpers/io.rb', line 26
def == other
to_s == other
end
|
#=~(other) ⇒ Object
30
31
32
|
# File 'lib/mspec/helpers/io.rb', line 30
def =~ other
to_s =~ other
end
|
46
47
48
49
50
|
# File 'lib/mspec/helpers/io.rb', line 46
def flush
@output += @buffer.join('')
@buffer.clear
self
end
|
59
60
61
|
# File 'lib/mspec/helpers/io.rb', line 59
def inspect
to_s.inspect
end
|
#print(*str) ⇒ Object
18
19
20
|
# File 'lib/mspec/helpers/io.rb', line 18
def print(*str)
write(str.join + $\.to_s)
end
|
#printf(format, *args) ⇒ Object
42
43
44
|
# File 'lib/mspec/helpers/io.rb', line 42
def printf(format, *args)
self << sprintf(format, *args)
end
|
#puts(*str) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/mspec/helpers/io.rb', line 34
def puts(*str)
if str.empty?
write "\n"
else
write(str.collect { |s| s.to_s.chomp }.concat([nil]).join("\n"))
end
end
|
#to_s ⇒ Object
Also known as:
to_str
52
53
54
55
|
# File 'lib/mspec/helpers/io.rb', line 52
def to_s
flush
@output
end
|
#write(*str) ⇒ Object
9
10
11
|
# File 'lib/mspec/helpers/io.rb', line 9
def write(*str)
self << str.join
end
|