Total Complexity | 2 |
Total Lines | 21 |
Duplicated Lines | 100 % |
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 | module Koine |
||
4 | View Code Duplication | class HashOf < Base |
|
|
|||
5 | def initialize(key_adapter, value_adapter) |
||
6 | @key_adapter = key_adapter || raise(ArgumentError, 'Invalid key adapter') |
||
7 | @value_adapter = value_adapter || raise(ArgumentError, 'Invalid value adapter') |
||
8 | with_default_value({}) |
||
9 | end |
||
10 | |||
11 | private |
||
12 | |||
13 | def coerce_not_nil(hash) |
||
14 | secure do |
||
15 | {}.tap do |new_hash| |
||
16 | hash.each do |key, value| |
||
17 | key = @key_adapter.coerce(key) |
||
18 | value = @value_adapter.coerce(value) |
||
19 | new_hash[key] = value |
||
20 | end |
||
21 | end |
||
22 | end |
||
23 | end |
||
24 | end |
||
25 | end |
||
28 |