class Primalize::Single::Any

Public Class Methods

new(types, &coercion) click to toggle source
# File lib/primalize/single.rb, line 384
def initialize types, &coercion
  @types = types
  @coercion = coercion
end

Public Instance Methods

===(value) click to toggle source
# File lib/primalize/single.rb, line 389
def === value
  @types.empty? || @types.any? { |type| type === value }
end
coerce(value) click to toggle source
# File lib/primalize/single.rb, line 393
def coerce value
  if @coercion
    return @coercion.call(value)
  end

  type = @types.find { |type| type === value }
  if type.respond_to? :coerce
    type.coerce(value)
  else
    value
  end
end
inspect() click to toggle source
# File lib/primalize/single.rb, line 406
def inspect
  params = "(#{@types.map(&:inspect).join(', ')})"
  "any#{@types.empty? ? nil : params}"
end