Exception: RBS::DuplicatedMethodDefinitionError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, method_name:, members:) ⇒ DuplicatedMethodDefinitionError

Returns a new instance of DuplicatedMethodDefinitionError.



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/rbs/errors.rb', line 182

def initialize(type:, method_name:, members:)
  @type = type
  @method_name = method_name
  @members = members

  message = "#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
  if members.size > 1
    message << " in #{other_locations.map { |loc| Location.to_string loc }.join(', ')}"
  end
  super message
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



180
181
182
# File 'lib/rbs/errors.rb', line 180

def members
  @members
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



179
180
181
# File 'lib/rbs/errors.rb', line 179

def method_name
  @method_name
end

#typeObject (readonly)

Returns the value of attribute type.



178
179
180
# File 'lib/rbs/errors.rb', line 178

def type
  @type
end

Instance Method Details

#locationObject



203
204
205
# File 'lib/rbs/errors.rb', line 203

def location
  members[0].location
end

#other_locationsObject



207
208
209
# File 'lib/rbs/errors.rb', line 207

def other_locations
  members.drop(1).map(&:location)
end

#qualified_method_nameObject



194
195
196
197
198
199
200
201
# File 'lib/rbs/errors.rb', line 194

def qualified_method_name
  case type
  when Types::ClassSingleton
    "#{type.name}.#{method_name}"
  else
    "#{type.name}##{method_name}"
  end
end