Class: Ree::Contracts::ArgContracts::SubclassOf
- Extended by:
- Squarable
- Includes:
- Truncatable
- Defined in:
- lib/ree/contracts/arg_contracts/subclass_of.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass) ⇒ SubclassOf
constructor
A new instance of SubclassOf.
- #message(value, name, lvl = 1) ⇒ Object
- #to_s ⇒ Object
- #valid?(value) ⇒ Boolean
Methods included from Squarable
Methods included from Truncatable
Constructor Details
#initialize(klass) ⇒ SubclassOf
Returns a new instance of SubclassOf.
11 12 13 |
# File 'lib/ree/contracts/arg_contracts/subclass_of.rb', line 11 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/ree/contracts/arg_contracts/subclass_of.rb', line 9 def klass @klass end |
Instance Method Details
#message(value, name, lvl = 1) ⇒ Object
23 24 25 |
# File 'lib/ree/contracts/arg_contracts/subclass_of.rb', line 23 def (value, name, lvl = 1) "expected #{truncate(self.to_s, 30)}, got #{truncate(value.inspect)}" end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/ree/contracts/arg_contracts/subclass_of.rb', line 19 def to_s "SubclassOf[#{klass.inspect}]" end |
#valid?(value) ⇒ Boolean
15 16 17 |
# File 'lib/ree/contracts/arg_contracts/subclass_of.rb', line 15 def valid?(value) value.is_a?(Class) && value < klass end |