class NRSER::Types::ArrayOfType

Type for arrays where every entry satisfies a specific type.

Broken out from {ArrayType} so that {TupleType} can inherit from {ArrayType} and get share it's string handling functionality without receiving the entry type stuff (which it handles differently).

Attributes

item_type[R]

Type that all items must satisfy for an array to be a member of this type.

@return [NRSER::Types::Type]

Public Class Methods

new(item_type, **options) click to toggle source

Instantiate a new `ArrayOfType`.

Calls superclass method NRSER::Types::ArrayType::new
# File lib/nrser/types/arrays.rb, line 128
def initialize item_type, **options
  super **options
  @item_type = NRSER::Types.make item_type
end

Public Instance Methods

==(other) click to toggle source

@todo

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?
# File lib/nrser/types/arrays.rb, line 178
def == other
  equal?(other) || (
    other.class == self.class && @item_type == other.item_type
  )
end
explain() click to toggle source

@!group Display Instance Methods


# File lib/nrser/types/arrays.rb, line 140
def explain
  "Array<#{ item_type.explain }>"
end
has_from_s?() click to toggle source

{ArrayOfType} can convert values from strings if it's {#item_type} can convert values from strings.

@return [Boolean]

# File lib/nrser/types/arrays.rb, line 162
def has_from_s?
  @from_s || @item_type.has_from_s?
end
items_from_strings(items) click to toggle source
# File lib/nrser/types/arrays.rb, line 167
def items_from_strings items
  items.map &@item_type.method( :from_s )
end
test?(value) click to toggle source

@!endgroup Display Instance Methods # ************************************

Calls superclass method
# File lib/nrser/types/arrays.rb, line 147
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