Class: Laser::Types::UnionType

Inherits:
Base
  • Object
show all
Defined in:
lib/laser/types/types.rb

Instance Method Summary collapse

Methods inherited from Base

#==, #eql?, #hash, #|

Methods included from ActsAsStruct

#acts_as_struct

Constructor Details

#initialize(member_types) ⇒ UnionType



68
69
70
# File 'lib/laser/types/types.rb', line 68

def initialize(member_types)
  @member_types = Set.new(flatten_unions(member_types))
end

Instance Method Details

#flatten_unions(types) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/laser/types/types.rb', line 72

def flatten_unions(types)
  result = []
  types.each do |type|
    if UnionType === type
      result += type.member_types.to_a
    else
      result << type
    end
  end
  result
end

#matching_methods(name) ⇒ Object



97
98
99
100
# File 'lib/laser/types/types.rb', line 97

def matching_methods(name)
  name = name.to_sym
  member_types.map { |type| type.matching_methods(name) }.flatten.uniq
end

#possible_classesObject



88
89
90
# File 'lib/laser/types/types.rb', line 88

def possible_classes
  member_types.map { |type| type.possible_classes }.inject(:|) || Set[]
end

#public_matching_methods(name) ⇒ Object



92
93
94
95
# File 'lib/laser/types/types.rb', line 92

def public_matching_methods(name)
  name = name.to_sym
  member_types.map { |type| type.public_matching_methods(name) }.flatten.uniq
end

#signatureObject



84
85
86
# File 'lib/laser/types/types.rb', line 84

def signature
  {member_types: member_types}
end