Class: TestMe::Double
- Inherits:
-
Object
show all
- Defined in:
- lib/double.rb
Instance Method Summary
collapse
Constructor Details
#initialize(subject = nil) ⇒ Double
Returns a new instance of Double.
3
4
5
6
|
# File 'lib/double.rb', line 3
def initialize subject=nil
@subject = subject if subject
@dict = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/double.rb', line 8
def method_missing(method, *args, &block)
if @subject
if @subject.respond_to?(method) && !@dict.key?(method)
return @subject.send(method, *args, &block)
end
end
if method.to_s =~ /=$/
return @dict[method.to_s.match(/^(.*)=$/)[1].to_sym] = args.first
else
return @dict[method] ||= Double.new
end
end
|
Instance Method Details
#class ⇒ Object
26
27
28
|
# File 'lib/double.rb', line 26
def class
return @subject.class
end
|
#test(*args, &block) ⇒ Object
22
23
24
|
# File 'lib/double.rb', line 22
def test *args, &block
method_missing :test, *args, &block
end
|
#to_str ⇒ Object
30
31
32
|
# File 'lib/double.rb', line 30
def to_str
return @subject.to_s
end
|