Class: NRSER::Types::ArrayOfType
- Defined in:
- lib/nrser/types/arrays.rb
Overview
Constant Summary
Constants inherited from ArrayType
NRSER::Types::ArrayType::DEFAULT_SPLIT_WITH
Instance Attribute Summary collapse
-
#item_type ⇒ NRSER::Types::Type
readonly
Type that all items must satisfy for an array to be a member of this type.
Attributes inherited from IsA
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#explain ⇒ Object
Instance Methods ======================================================================.
-
#has_from_s? ⇒ Boolean
ArrayOfType can convert values from strings if it’s #item_type can convert values from strings.
-
#initialize(item_type, **options) ⇒ ArrayOfType
constructor
Instantiate a new ‘ArrayOfType`.
- #items_from_strings(items) ⇒ Object
- #test?(value) ⇒ Boolean
Methods inherited from ArrayType
Methods inherited from IsA
#custom_from_data, #has_from_data?, #init_from_data?
Methods inherited from Type
#===, #builtin_inspect, #check, #check!, #from_data, #from_s, #has_from_data?, #has_to_data?, #inspect, #intersection, #name, #not, #respond_to?, #test, #to_data, #to_s, #union, #xor
Constructor Details
#initialize(item_type, **options) ⇒ ArrayOfType
Instantiate a new ‘ArrayOfType`.
93 94 95 96 |
# File 'lib/nrser/types/arrays.rb', line 93 def initialize item_type, ** super ** @item_type = NRSER::Types.make item_type end |
Instance Attribute Details
#item_type ⇒ NRSER::Types::Type (readonly)
Type that all items must satisfy for an array to be a member of this type.
86 87 88 |
# File 'lib/nrser/types/arrays.rb', line 86 def item_type @item_type end |
Instance Method Details
#==(other) ⇒ Object
I’m not even sure why this is implemented… was it used somewhere?
It doesn’t seems too well thought out… seems like the reality of comparing types is much more complicated?
138 139 140 141 142 |
# File 'lib/nrser/types/arrays.rb', line 138 def == other equal?(other) || ( other.class == self.class && @item_type == other.item_type ) end |
#explain ⇒ Object
Instance Methods
102 103 104 |
# File 'lib/nrser/types/arrays.rb', line 102 def explain "#{ super() }<#{ item_type.explain }>" end |
#has_from_s? ⇒ Boolean
NRSER::Types::ArrayOfType can convert values from strings if it’s #item_type can convert values from strings.
122 123 124 |
# File 'lib/nrser/types/arrays.rb', line 122 def has_from_s? @from_s || @item_type.has_from_s? end |
#items_from_strings(items) ⇒ Object
127 128 129 |
# File 'lib/nrser/types/arrays.rb', line 127 def items_from_strings items items.map &@item_type.method( :from_s ) end |
#test?(value) ⇒ Boolean
107 108 109 110 111 112 113 114 |
# File 'lib/nrser/types/arrays.rb', line 107 def test? value # Check the super method first, which will test if `value` is an Array # instance, and return `false` if it's not. return false unless super( value ) # Otherwise test all the items value.all? &@item_type.method( :test ) end |