123456789_123456789_123456789_123456789_123456789_

Class: RBS::Definition::Method

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil) ⇒ Method

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 102

def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil)
  @super_method = super_method
  @defs = defs
  @accessibility = accessibility
  @extra_annotations = []
  @annotations = []
  @alias_of = alias_of
  @alias_member = alias_member
end

Instance Attribute Details

#accessibility (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 96

attr_reader :accessibility

#alias_member (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 100

attr_reader :alias_member

#alias_of (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 99

attr_reader :alias_of

#annotations (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 98

attr_reader :annotations

#defs (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 95

attr_reader :defs

#extra_annotations (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 97

attr_reader :extra_annotations

#private?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 158

def private?
  @accessibility == :private
end

#public?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 154

def public?
  @accessibility == :public
end

#super_method (readonly)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 94

attr_reader :super_method

Instance Method Details

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 112

def ==(other)
  other.is_a?(Method) &&
    other.super_method == super_method &&
    other.defs == defs &&
    other.accessibility == accessibility &&
    other.annotations == annotations &&
    other.alias_of == alias_of &&
    other.alias_member == alias_member
end

#comments

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 146

def comments
  @comments ||= defs.map(&:comment).compact.uniq
end

#defined_in

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 128

def defined_in
  @defined_in ||= begin
    last_def = defs.last or raise
    last_def.defined_in
  end
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 122

alias eql? ==

#hash

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 124

def hash
  self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash
end

#implemented_in

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 135

def implemented_in
  @implemented_in ||= begin
    last_def = defs.last or raise
    last_def.implemented_in
  end
end

#map_method_type(&block)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 185

def map_method_type(&block)
  update(
    defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
  )
end

#map_type(&block)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 171

def map_type(&block)
  update(
    super_method: super_method&.map_type(&block),
    defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) }
  )
end

#map_type_bound(&block)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 178

def map_type_bound(&block)
  update(
    super_method: super_method&.map_type_bound(&block),
    defs: defs.map {|defn| defn.update(type: defn.type.map_type_bound(&block)) }
  )
end

#members

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 150

def members
  @members ||= defs.map(&:member).uniq
end

#method_types

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 142

def method_types
  @method_types ||= defs.map(&:type)
end

#sub(s)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 162

def sub(s)
  return self if s.empty?

  update(
    super_method: super_method&.sub(s),
    defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) }
  )
end

#update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member)

[ GitHub ]

  
# File 'lib/rbs/definition.rb', line 191

def update(super_method: self.super_method, defs: self.defs, accessibility: self.accessibility, alias_of: self.alias_of, annotations: self.annotations, alias_member: self.alias_member)
  self.class.new(
    super_method: super_method,
    defs: defs,
    accessibility: accessibility,
    alias_of: alias_of,
    alias_member: alias_member
  ).tap do |method|
    method.annotations.replace(annotations)
  end
end