Class: Mal::UnionT
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #&(another) ⇒ Object
- #===(value) ⇒ Object
-
#initialize(*types) ⇒ UnionT
constructor
A new instance of UnionT.
- #inspect ⇒ Object
Methods inherited from OnlyT
Constructor Details
#initialize(*types) ⇒ UnionT
Returns a new instance of UnionT.
242 243 244 |
# File 'lib/mal.rb', line 242 def initialize(*types) @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
241 242 243 |
# File 'lib/mal.rb', line 241 def types @types end |
Instance Method Details
#&(another) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/mal.rb', line 254 def &(another) if another.is_a?(UnionT) unique_types = (@types + another.types).uniq return UnionT.new(*unique_types) end super end |
#===(value) ⇒ Object
246 247 248 |
# File 'lib/mal.rb', line 246 def ===(value) @types.all? {|type| type === value} end |
#inspect ⇒ Object
250 251 252 |
# File 'lib/mal.rb', line 250 def inspect 'Both(%s)' % @types.map{|e| e.inspect }.join(', ') end |