Sha256: 93000c17547c019ec800a27ece2110155ef9a3a00c0fef384908acc88ab61c93

Contents?: true

Size: 976 Bytes

Versions: 9

Compression:

Stored size: 976 Bytes

Contents

Hash.class_eval do
  # Merges self with another hash, recursively.
  #
  # This code was lovingly stolen from some random gem:
  # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
  #
  # Thanks to whoever made it.
  def deep_merge(hash)
    target = dup

    hash.keys.each do |key|
      if hash[key].is_a? Hash and self[key].is_a? Hash
        target[key] = target[key].deep_merge(hash[key])
        next
      end

      target[key] = hash[key]
    end

    target
  end
  
  def deep_merge!(second)
    second.each_pair do |k,v|
      if self[k].is_a?(Hash) and second[k].is_a?(Hash)
        self[k].deep_merge!(second[k])
      else
        self[k] = second[k]
      end
    end
  end

  def symbolize!
    keys.each do |key|
      self[key].symbolize! if self[key].is_a?(Hash)
      self[key.to_sym] = self.delete(key)
    end
    self
  end
end

class String
  def camelize
    self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trinidad-0.9.4 lib/trinidad/core_ext.rb
trinidad-0.9.3 lib/trinidad/core_ext.rb
trinidad-0.9.2 lib/trinidad/core_ext.rb
trinidad-0.9.1 lib/trinidad/core_ext.rb
trinidad-0.9.0 lib/trinidad/core_ext.rb
trinidad-0.8.3 lib/trinidad/core_ext.rb
trinidad-0.8.2 lib/trinidad/core_ext.rb
trinidad-0.8.1 lib/trinidad/core_ext.rb
trinidad-0.8.0 lib/trinidad/core_ext.rb