Class: RBS::DefinitionBuilder::MethodBuilder::Methods

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/definition_builder/method_builder.rb

Defined Under Namespace

Classes: Definition, Sorter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:) ⇒ Methods

Returns a new instance of Methods.



30
31
32
33
# File 'lib/rbs/definition_builder/method_builder.rb', line 30

def initialize(type:)
  @type = type
  @methods = {}
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



28
29
30
# File 'lib/rbs/definition_builder/method_builder.rb', line 28

def methods
  @methods
end

#typeObject (readonly)

Returns the value of attribute type.



27
28
29
# File 'lib/rbs/definition_builder/method_builder.rb', line 27

def type
  @type
end

Instance Method Details

#eachObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rbs/definition_builder/method_builder.rb', line 49

def each
  if block_given?
    Sorter.new(methods).each_strongly_connected_component do |scc|
      if scc.size > 1
        raise RecursiveAliasDefinitionError.new(type: type, defs: scc)
      end

      yield scc[0]
    end
  else
    enum_for :each
  end
end

#validate!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbs/definition_builder/method_builder.rb', line 35

def validate!
  methods.each_value do |defn|
    if defn.originals.size > 1
      raise DuplicatedMethodDefinitionError.new(
        type: type,
        method_name: defn.name,
        members: defn.originals
      )
    end
  end

  self
end