Class: Monolens::Type::Any
- Inherits:
-
Object
- Object
- Monolens::Type::Any
- Includes:
- ErrorHandling
- Defined in:
- lib/monolens/type/any.rb
Class Method Summary collapse
Instance Method Summary collapse
- #===(instance) ⇒ Object
- #dress(instance, registry, &block) ⇒ Object
-
#initialize(candidates) ⇒ Any
constructor
A new instance of Any.
Methods included from ErrorHandling
Constructor Details
#initialize(candidates) ⇒ Any
Returns a new instance of Any.
6 7 8 |
# File 'lib/monolens/type/any.rb', line 6 def initialize(candidates) @candidates = candidates end |
Class Method Details
.===(instance) ⇒ Object
18 19 20 |
# File 'lib/monolens/type/any.rb', line 18 def self.===(instance) true end |
.dress(instance, registry) ⇒ Object
14 15 16 |
# File 'lib/monolens/type/any.rb', line 14 def self.dress(instance, registry) instance end |
Instance Method Details
#===(instance) ⇒ Object
22 23 24 |
# File 'lib/monolens/type/any.rb', line 22 def ===(instance) @candidates.any?{|c| c === instance } end |
#dress(instance, registry, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/monolens/type/any.rb', line 26 def dress(instance, registry, &block) first_error = nil @candidates.each do |candidate| begin return candidate.dress(instance, registry, &block) rescue TypeError => ex first_error ||= ex end end fail!(first_error., &block) end |