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

- (UnionType) initialize(member_types)

Returns a new instance of 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

- (Object) flatten_unions(types)



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

- (Object) matching_methods(name)



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

- (Object) possible_classes



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

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

- (Object) public_matching_methods(name)



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

- (Object) signature



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

def signature
  {member_types: member_types}
end