Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/kintsugi/utils.rb,
lib/kintsugi/apply_change_to_project.rb
Overview
Copyright © 2021 Lightricks. All rights reserved. Created by Ben Yohay. frozen_string_literal: true
Instance Method Summary collapse
-
#deep_clone ⇒ Array
Provides a deep clone of ‘self`.
-
#to_multi_h ⇒ Object
Converts an array of arrays of size 2 into a multimap, mapping the first element of each subarray to an array of the last elements it appears with in the same subarray.
Instance Method Details
#deep_clone ⇒ Array
Provides a deep clone of ‘self`
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kintsugi/utils.rb', line 9 def deep_clone map do |value| begin value.deep_clone rescue NoMethodError value.clone end rescue NoMethodError value end end |
#to_multi_h ⇒ Object
Converts an array of arrays of size 2 into a multimap, mapping the first element of each subarray to an array of the last elements it appears with in the same subarray.
16 17 18 19 20 21 22 |
# File 'lib/kintsugi/apply_change_to_project.rb', line 16 def to_multi_h raise ArgumentError, "Not all elements are arrays of size 2" unless all? do |arr| arr.is_a?(Array) && arr.count == 2 end group_by(&:first).transform_values { |group| group.map(&:last) } end |