Class: Philosophal::Types::ArrayOfType
- Inherits:
-
Object
- Object
- Philosophal::Types::ArrayOfType
- Defined in:
- lib/philosophal/types/array_of_type.rb
Instance Attribute Summary collapse
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
Class Method Summary collapse
Instance Method Summary collapse
- #===(array) ⇒ Object
-
#initialize(subtype) ⇒ ArrayOfType
constructor
A new instance of ArrayOfType.
Constructor Details
#initialize(subtype) ⇒ ArrayOfType
Returns a new instance of ArrayOfType.
18 19 20 21 |
# File 'lib/philosophal/types/array_of_type.rb', line 18 def initialize(subtype) @subtype = subtype self.class.memorization[subtype] = self end |
Instance Attribute Details
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
16 17 18 |
# File 'lib/philosophal/types/array_of_type.rb', line 16 def subtype @subtype end |
Class Method Details
.instance(subtype) ⇒ Object
6 7 8 |
# File 'lib/philosophal/types/array_of_type.rb', line 6 def self.instance(subtype) memorization.fetch(subtype, new(subtype).freeze) end |
.memorization ⇒ Object
10 11 12 13 14 |
# File 'lib/philosophal/types/array_of_type.rb', line 10 def self.memorization return @memorization if defined?(@memorization) @memorization = {} end |
Instance Method Details
#===(array) ⇒ Object
23 24 25 |
# File 'lib/philosophal/types/array_of_type.rb', line 23 def ===(array) array.is_a?(Array) && !array.find { |entry| !entry.is_a?(@subtype) } end |