Class: Mal::UnionT

Inherits:
OnlyT
  • Object
show all
Defined in:
lib/mal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typesObject (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

#inspectObject



250
251
252
# File 'lib/mal.rb', line 250

def inspect
  'Both(%s)' % @types.map{|e| e.inspect }.join(', ')
end