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.



107
108
109
110
111
112
113
114
115
# File '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

Instance Attribute Details

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



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

def accessibility
  @accessibility
end

#alias_memberObject (readonly)

Returns the value of attribute alias_member.



105
106
107
# File 'lib/rbs/definition.rb', line 105

def alias_member
  @alias_member
end

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



104
105
106
# File 'lib/rbs/definition.rb', line 104

def alias_of
  @alias_of
end

#annotationsObject (readonly)

Returns the value of attribute annotations.



103
104
105
# File 'lib/rbs/definition.rb', line 103

def annotations
  @annotations
end

#defsObject (readonly)

Returns the value of attribute defs.



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

def defs
  @defs
end

#extra_annotationsObject (readonly)

Returns the value of attribute extra_annotations.



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

def extra_annotations
  @extra_annotations
end

#super_methodObject (readonly)

Returns the value of attribute super_method.



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

def super_method
  @super_method
end

Instance Method Details

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



117
118
119
120
121
122
123
124
125
# File '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

#commentsObject



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

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

#defined_inObject



133
134
135
136
137
138
# File 'lib/rbs/definition.rb', line 133

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

#hashObject



129
130
131
# File 'lib/rbs/definition.rb', line 129

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

#implemented_inObject



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

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

#map_method_type(&block) ⇒ Object



190
191
192
193
194
# File 'lib/rbs/definition.rb', line 190

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

#map_type(&block) ⇒ Object



176
177
178
179
180
181
# File '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

#map_type_bound(&block) ⇒ Object



183
184
185
186
187
188
# File '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

#membersObject



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

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

#method_typesObject



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

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

#private?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/rbs/definition.rb', line 163

def private?
  @accessibility == :private
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  @accessibility == :public
end

#sub(s) ⇒ Object



167
168
169
170
171
172
173
174
# File '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

#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



196
197
198
199
200
201
202
203
204
205
206
# File '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