class Hash

Public Instance Methods

boolean_to_string!() click to toggle source

converts each value that is a boolean to ‘yes’ resp. ‘no’ strings

# File lib/dust/helper.rb, line 43
def boolean_to_string!
  self.each do |k, v|
    self[k] = 'yes' if v.is_a? TrueClass
    self[k] = 'no' if v.is_a? FalseClass

    # recursion
    v.boolean_to_string! if v.is_a? Hash
  end
end
deep_merge(other_hash) click to toggle source

stole this from rails Returns a new hash with self and other_hash merged recursively.

# File lib/dust/helper.rb, line 22
def deep_merge(other_hash)
  dup.deep_merge!(other_hash)
end
deep_merge!(other_hash) click to toggle source

Returns a new hash with self and other_hash merged recursively. Modifies the receiver in place.

# File lib/dust/helper.rb, line 28
def deep_merge!(other_hash)
  other_hash.each_pair do |k,v|
    tv = self[k]
    self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
  end
  self
end
values_to_array!() click to toggle source

converts each value to an array, so .each and .combine won’t get hickups

# File lib/dust/helper.rb, line 38
def values_to_array!
  self.keys.each { |k| self[k] = Array(self[k]) }
end