Class: Contracts::Builtin::Exactly
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Exactly
- Defined in:
- lib/contracts/builtin_contracts.rb
Overview
Takes a class A
. If argument is object of type A
, the contract passes. If it is a subclass of A (or not related to A in any way), it fails. Example: Exactly[Numeric]
Instance Method Summary collapse
-
#initialize(cls) ⇒ Exactly
constructor
A new instance of Exactly.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(cls) ⇒ Exactly
Returns a new instance of Exactly.
219 220 221 222 |
# File 'lib/contracts/builtin_contracts.rb', line 219 def initialize(cls) super() @cls = cls end |
Instance Method Details
#to_s ⇒ Object
228 229 230 |
# File 'lib/contracts/builtin_contracts.rb', line 228 def to_s "exactly #{@cls.inspect}" end |
#valid?(val) ⇒ Boolean
224 225 226 |
# File 'lib/contracts/builtin_contracts.rb', line 224 def valid?(val) val.instance_of?(@cls) end |