Class: Highway::Steps::Types::Set

Inherits:
Array
  • Object
show all
Defined in:
lib/highway/steps/types/set.rb

Overview

This class represents a set parameter type. It’s like array but ensures the values occur only once.

Instance Method Summary collapse

Methods inherited from Array

#initialize

Methods inherited from Any

#initialize, #typecheck_and_validate, #validate

Constructor Details

This class inherits a constructor from Highway::Steps::Types::Array

Instance Method Details

#typecheck(value) ⇒ Set?

Typecheck and coerce a value if possible.

This method returns a typechecked and coerced value or ‘nil` if value has invalid type and can’t be coerced.

Parameters:

  • value (Object)

    A value.

Returns:



28
29
30
31
32
33
# File 'lib/highway/steps/types/set.rb', line 28

def typecheck(value)
  typechecked_array = super(value)
  return nil if typechecked_array == nil
  typechecked_set = ::Set.new(typechecked_array)
  typechecked_set if typechecked_set.count == typechecked_array.count
end