SHOW:
|
|
- or go back to the newest paste.
| 1 | def CustomMergingCollection | |
| 2 | include Enumerable | |
| 3 | ||
| 4 | def initialize(hash={}) | |
| 5 | @hash = hash | |
| 6 | end | |
| 7 | ||
| 8 | def each(&block) | |
| 9 | @hash.values.each(&block) | |
| 10 | end | |
| 11 | ||
| 12 | def []=(other) | |
| 13 | idx = other.idx | |
| 14 | return @hash[idx] = other unless @hash[idx] | |
| 15 | @hash[idx] = combine(current, other) | |
| 16 | end | |
| 17 | ||
| 18 | private | |
| 19 | ||
| 20 | def combine(first, second) | |
| 21 | # ... | |
| 22 | end | |
| 23 | end |