Class: Contracts::Builtin::Exactly
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Exactly
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/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.
206 207 208 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 206 def initialize(cls) @cls = cls end |
Instance Method Details
#to_s ⇒ Object
214 215 216 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 214 def to_s "exactly #{@cls.inspect}" end |
#valid?(val) ⇒ Boolean
210 211 212 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 210 def valid?(val) val.class == @cls end |