Class: Gimme::TestDouble
Constant Summary
collapse
- @@gimme_count =
0
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(cls_or_name = nil) ⇒ TestDouble
Returns a new instance of TestDouble.
15
16
17
18
19
|
# File 'lib/gimme/test_double.rb', line 15
def initialize(cls_or_name=nil)
@name = cls_or_name
@cls = cls_or_name if cls_or_name.kind_of?(Class)
@gimme_id = (@@gimme_count += 1)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Instance Attribute Details
#cls ⇒ Object
Returns the value of attribute cls.
10
11
12
|
# File 'lib/gimme/test_double.rb', line 10
def cls
@cls
end
|
Instance Method Details
#==(other, *args, &blk) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/gimme/test_double.rb', line 59
def ==(other, *args, &blk)
if stubbed?(:==, other, *args, &blk)
method_missing(:==, other, *args, &blk)
else
eql?(other)
end
end
|
#eql?(other, *args, &blk) ⇒ Boolean
51
52
53
54
55
56
57
|
# File 'lib/gimme/test_double.rb', line 51
def eql?(other, *args, &blk)
if stubbed?(:eql?, other, *args, &blk)
method_missing(:eql?, other, *args, &blk)
else
__id__ == other.__id__
end
end
|
#hash(*args, &blk) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/gimme/test_double.rb', line 43
def hash(*args, &blk)
if stubbed?(:hash, *args, &blk)
method_missing(:hash, *args, &blk)
else
__id__
end
end
|
#inspect(*args, &blk) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/gimme/test_double.rb', line 27
def inspect(*args, &blk)
if stubbed?(:inspect, *args, &blk)
method_missing(:inspect, *args, &blk)
else
"<#Gimme:#{@gimme_id} #{@name}>"
end
end
|
#to_s(*args, &blk) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/gimme/test_double.rb', line 35
def to_s(*args, &blk)
if stubbed?(:to_s, *args, &blk)
method_missing(:to_s, *args, &blk)
else
inspect
end
end
|