123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: lib/rbs/definition_builder/method_builder.rb

Constant Summary

  • Definition =
    # File 'lib/rbs/definition_builder/method_builder.rb', line 5
    _ = Struct.new(:name, :type, :originals, :overloads, :accessibilities, keyword_init: true) do
      # @implements Definition
    
      def original
        originals.first
      end
    
      def accessibility
        accessibilities[0]
      end
    
      def self.empty(name:, type:)
        new(type: type, name: name, originals: [], overloads: [], accessibilities: [])
      end
    end

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(type:) ⇒ Methods

[ GitHub ]

  
# File 'lib/rbs/definition_builder/method_builder.rb', line 24

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

Instance Attribute Details

#methods (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition_builder/method_builder.rb', line 22

attr_reader :methods

#type (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition_builder/method_builder.rb', line 21

attr_reader :type

Instance Method Details

#each

[ GitHub ]

  
# File 'lib/rbs/definition_builder/method_builder.rb', line 43

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!

[ GitHub ]

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

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