Class: Contracts::Builtin::DescendantOf
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::DescendantOf
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb
Overview
Use this for specifying contracts for class arguments Example: DescendantOf[ e: Range, f: Optional[Num] ]
Instance Method Summary collapse
-
#initialize(parent_class) ⇒ DescendantOf
constructor
A new instance of DescendantOf.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #valid?(given_class) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(parent_class) ⇒ DescendantOf
Returns a new instance of DescendantOf.
447 448 449 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 447 def initialize(parent_class) @parent_class = parent_class end |
Instance Method Details
#inspect ⇒ Object
459 460 461 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 459 def inspect to_s end |
#to_s ⇒ Object
455 456 457 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 455 def to_s "DescendantOf[#{parent_class}]" end |
#valid?(given_class) ⇒ Boolean
451 452 453 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 451 def valid?(given_class) given_class.is_a?(Class) && given_class.ancestors.include?(parent_class) end |