Class: T::AnyType
- Inherits:
-
Object
- Object
- T::AnyType
- Defined in:
- lib/emery/type.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #check(value) ⇒ Object
-
#initialize(*types) ⇒ AnyType
constructor
A new instance of AnyType.
- #to_s ⇒ Object
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
#types ⇒ Object (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_s ⇒ Object
40 41 42 |
# File 'lib/emery/type.rb', line 40 def to_s "Any[#{types.map { |t| t.to_s}.join(', ')}]" end |