class TrelloFreestyler::Utils
Public Class Methods
deep_clean(hash)
click to toggle source
# 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)
click to toggle source
# File lib/trello_freestyler/utils/hash.rb, line 26 def self.deep_copy(obj) Marshal.load(Marshal.dump(obj)) end
deep_deep_clean(hash)
click to toggle source
# 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