Sha256: 3e10f8d0bbf7bb58c2eb5f255f8ef9774c882f4585fb0a55bb03b5ad95334217

Contents?: true

Size: 615 Bytes

Versions: 11

Compression:

Stored size: 615 Bytes

Contents

Hash.class_eval do
  #take keys of hash and transform those to a symbols
  def self.symbolize_keys(item)
    if item.class == Hash
      item.to_options!
      item.each do |key, value|
        self.symbolize_keys(value)
      end
    elsif item.class == Array
      item.each do |array_val|
        self.symbolize_keys(array_val)
      end
    end

    item
  end

  #merge hash and overwrite key only if it is nil
  def apply_if(hash)
    self.merge(hash){|key, v1, v2| v1.nil? ? v2 : v1}
  end

  def apply_if!(hash)
    self.merge!(hash){|key, v1, v2| v1.nil? ? v2 : v1}
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
erp_base_erp_svcs-4.2.0 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-4.0.0 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.5 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.4 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.3 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.2 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.1 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.0.7 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.1.0 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.0.6 lib/erp_base_erp_svcs/extensions/core/hash.rb
erp_base_erp_svcs-3.0.5 lib/erp_base_erp_svcs/extensions/core/hash.rb