class RBS::Definition::Method
Attributes
accessibility
[R]
accessibility
alias_member
[R]
AST::Members::Alias?
Present if the method is defined with alias syntax
The original method when the method is defined with alias syntax
annotations
[R]
Array[AST::Annotation]
Union of annotations given to defs and alias, not contains annotations given to each overload
The elements will be updated during Method object setup.
extra_annotations
[R]
Array[AST::Annotation]
Unused, always returns empty array
Public Class Methods
(super_method: Method?, defs: Array[TypeDef], accessibility: accessibility, alias_of: Method?, alias_member: AST::Members::Alias?) → void
(super_method: Method?, defs: Array[TypeDef], accessibility: accessibility, alias_of: Method?, annotations: Array[AST::Annotation]) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 107 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
Note that the annotations given through annotations: keyword is ignored.
Public Instance Methods
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 117 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
Also aliased as: eql?
Array[AST::Comment]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 151 def comments @comments ||= defs.map(&:comment).compact.uniq end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 133 def defined_in @defined_in ||= begin last_def = defs.last or raise last_def.defined_in end end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 129 def hash self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 140 def implemented_in @implemented_in ||= begin last_def = defs.last or raise last_def.implemented_in end end
() { (MethodType) → MethodType } → Method
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 190 def map_method_type(&block) update( defs: defs.map {|defn| defn.update(type: yield(defn.type)) }, ) end
() { (Types::t) → Types::t } → Method
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 176 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
Applies the mapping from Types::t to Types::t.
Note this method doesnβt handle upper bound in type params. You may want to use map_type_bound explicitly, or sub for simple substitution.
() { (Types::t) → Types::t } → Method
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 183 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
Array[method_member]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 155 def members @members ||= defs.map(&:member).uniq end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 147 def method_types @method_types ||= defs.map(&:type) end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 163 def private? @accessibility == :private end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 159 def public? @accessibility == :public end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 167 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
Substitutes type variables to some types. Takes care of type parameter bounds.
(?super_method: Method?, ?defs: Array[TypeDef], ?accessibility: accessibility, ?alias_of: Method?, ?annotations: Array[AST::Annotation], ?alias_member: AST::Members::Alias?) → Method
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/definition.rb, line 196 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