Class: NRSER::Types::ArrayOfType
- Defined in:
- lib/nrser/types/array.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
-
#default_name ⇒ 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) ⇒ Object
Methods inherited from ArrayType
Methods inherited from Type
#check, #from_s, #has_to_data?, #name, #respond_to?, short_name, #to_data, #to_s
Constructor Details
#initialize(item_type, **options) ⇒ ArrayOfType
Instantiate a new ‘ArrayOfType`.
123 124 125 126 |
# File 'lib/nrser/types/array.rb', line 123 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.
116 117 118 |
# File 'lib/nrser/types/array.rb', line 116 def item_type @item_type end |
Instance Method Details
#==(other) ⇒ Object
168 169 170 171 172 |
# File 'lib/nrser/types/array.rb', line 168 def == other equal?(other) || ( other.class == self.class && @item_type == other.item_type ) end |
#default_name ⇒ Object
Instance Methods
132 133 134 |
# File 'lib/nrser/types/array.rb', line 132 def default_name "#{ super() }<#{ @item_type }>" end |
#has_from_s? ⇒ Boolean
NRSER::Types::ArrayOfType can convert values from strings if it’s #item_type can convert values from strings.
152 153 154 |
# File 'lib/nrser/types/array.rb', line 152 def has_from_s? @item_type.has_from_s? end |
#items_from_strings(items) ⇒ Object
157 158 159 |
# File 'lib/nrser/types/array.rb', line 157 def items_from_strings items items.map &@item_type.method( :from_s ) end |
#test(value) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/nrser/types/array.rb', line 137 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 |