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.
205 206 207 |
# File 'lib/contracts/builtin_contracts.rb', line 205 def initialize(cls) @cls = cls end |
Instance Method Details
#to_s ⇒ Object
213 214 215 |
# File 'lib/contracts/builtin_contracts.rb', line 213 def to_s "exactly #{@cls.inspect}" end |
#valid?(val) ⇒ Boolean
209 210 211 |
# File 'lib/contracts/builtin_contracts.rb', line 209 def valid?(val) val.class == @cls end |