Class: RBS::Definition::Method

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

Defined Under Namespace

Classes: TypeDef

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:, alias_member: nil) ⇒ Method

Returns a new instance of Method.



102
103
104
105
106
107
108
109
110
# 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

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



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

def accessibility
  @accessibility
end

#alias_memberObject (readonly)

Returns the value of attribute alias_member.



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

def alias_member
  @alias_member
end

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



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

def alias_of
  @alias_of
end

#annotationsObject (readonly)

Returns the value of attribute annotations.



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

def annotations
  @annotations
end

#defsObject (readonly)

Returns the value of attribute defs.



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

def defs
  @defs
end

#extra_annotationsObject (readonly)

Returns the value of attribute extra_annotations.



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

def extra_annotations
  @extra_annotations
end

#super_methodObject (readonly)

Returns the value of attribute super_method.



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

def super_method
  @super_method
end

Instance Method Details

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



112
113
114
115
116
117
118
119
120
# 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

#commentsObject



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

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

#defined_inObject



128
129
130
131
132
133
# 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

#hashObject



124
125
126
# 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_inObject



135
136
137
138
139
140
# 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) ⇒ Object



185
186
187
188
189
# 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) ⇒ Object



171
172
173
174
175
176
# 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) ⇒ Object



178
179
180
181
182
183
# 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

#membersObject



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

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

#method_typesObject



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

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

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  @accessibility == :private
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  @accessibility == :public
end

#sub(s) ⇒ Object



162
163
164
165
166
167
168
169
# 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) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
# 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