| Total Complexity | 1 |
| Total Lines | 14 |
| Duplicated Lines | 42.86 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 4 | class StudyEventInstrument < ApplicationRecord |
||
| 5 | belongs_to :study_event, inverse_of: :study_event_instruments |
||
| 6 | belongs_to :instrument, inverse_of: :study_event_instruments |
||
| 7 | |||
| 8 | validates :study_event, presence: true |
||
| 9 | validates :instrument, presence: true |
||
| 10 | |||
| 11 | validates_uniqueness_of :instrument, scope: :study_event |
||
| 12 | View Code Duplication | validates_uniqueness_of :study_event, scope: :instrument |
|
|
|
|||
| 13 | |||
| 14 | def to_s |
||
| 15 | "#{study_event} #{instrument}" |
||
| 16 | end |
||
| 17 | end |
||
| 18 | |||
| 35 |