Exception: ArgumentError
- Inherits:
-
Exception
- Object
- Exception
- ArgumentError
show all
- Defined in:
- lib/gorillib/exception/raisers.rb
Class Method Summary
collapse
Class Method Details
.check_type!(obj, types, *args) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/gorillib/exception/raisers.rb', line 117
def self.check_type!(obj, types, *args)
types = Array(types)
return true if types.any? do |type|
case type
when Module then obj.is_a?(type)
when Symbol then obj.respond_to?(type)
else raise StandardError, "Can't check type #{type} -- this is an error in the call to the type-checker, not in the object the type-checker is checking"
end
end
self.mismatched!(obj, types, *args)
end
|
.mismatched!(obj, types = [], msg = nil, *args) ⇒ Object
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/gorillib/exception/raisers.rb', line 94
def self.mismatched!(obj, types=[], msg=nil, *args)
types = Array(types)
message = (obj.inspect rescue '(uninspectable object)')
message << " has mismatched type"
message << ': ' << msg if msg
unless types.empty?
message << '; expected ' << types.map{|type| type.is_a?(Symbol) ? "##{type}" : type.to_s }.join(" or ")
end
raise self, message, *args
end
|