Total Complexity | 5 |
Total Lines | 32 |
Duplicated Lines | 12.5 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | # frozen_string_literal: true |
||
12 | class Parameter < Type |
||
13 | attr_reader :owner |
||
14 | attr_reader :id |
||
15 | |||
16 | # @param [AMA::Entity::Mapper::Type] owner |
||
17 | # @param [Symbol] id |
||
18 | def initialize(owner, id) |
||
19 | @owner = owner |
||
20 | @id = id |
||
21 | end |
||
22 | |||
23 | def to_s |
||
24 | "Parameter (reference) type for variable type :#{id} " \ |
||
25 | "(declared in #{owner})" |
||
26 | end |
||
27 | |||
28 | def hash |
||
29 | @owner.hash ^ @id.hash |
||
30 | end |
||
31 | |||
32 | View Code Duplication | def eql?(other) |
|
|
|||
33 | return false unless other.is_a?(self.class) |
||
34 | @owner == other.owner && @id == other.id |
||
35 | end |
||
36 | |||
37 | Type.instance_methods.each do |method| |
||
38 | next if method_defined?(method) |
||
39 | define_method(method) do |*args| |
||
40 | @owner.parameters[@id].send(method, *args) |
||
41 | end |
||
42 | end |
||
43 | end |
||
44 | end |
||
48 |