Class: TrelloFreestyler::Utils
- Inherits:
-
Object
- Object
- TrelloFreestyler::Utils
- Defined in:
- lib/trello_freestyler/utils/hash.rb
Class Method Summary collapse
Class Method Details
.deep_clean(hash) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/trello_freestyler/utils/hash.rb', line 17 def self.deep_clean(hash) return hash unless hash.is_a?(Hash) scrubed = hash.delete_if { |_, value| value == {} } scrubed.transform_values do |val| deep_clean(val) end end |
.deep_copy(obj) ⇒ Object
26 27 28 |
# File 'lib/trello_freestyler/utils/hash.rb', line 26 def self.deep_copy(obj) Marshal.load(Marshal.dump(obj)) end |
.deep_deep_clean(hash) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/trello_freestyler/utils/hash.rb', line 5 def self.deep_deep_clean(hash) # Sometimes removing one layer of empty objects creates another. # So loop until cleaning is no longer detecting changes. current_state = deep_copy(hash) # Who knew that object mutation was bad loop do new_state = deep_clean(hash) return current_state if current_state == new_state current_state = new_state end end |