Class: T::AnyType

Inherits:
Object
  • Object
show all
Defined in:
lib/emery/type.rb

Direct Known Subclasses

UnionType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ AnyType

Returns a new instance of AnyType.



37
38
39
# File 'lib/emery/type.rb', line 37

def initialize(*types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



36
37
38
# File 'lib/emery/type.rb', line 36

def types
  @types
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/emery/type.rb', line 49

def ==(other)
  T.instance_of?(AnyType, other) and (self.types - other.types).empty?
end

#check(value) ⇒ Object



43
44
45
46
47
48
# File 'lib/emery/type.rb', line 43

def check(value)
  type = types.find {|t| T.instance_of?(t, value) }
  if type == nil
    raise TypeError.new("Value '#{value.inspect.to_s}' type is #{value.class} - any of #{@types.map { |t| t.to_s}.join(', ')} required")
  end
end

#to_sObject



40
41
42
# File 'lib/emery/type.rb', line 40

def to_s
  "Any[#{types.map { |t| t.to_s}.join(', ')}]"
end