Sha256: 493c2d6aa876dc5355d45e42ccf2c035ab825e5edd6bc73e43384b15aec2e5e6

Contents?: true

Size: 980 Bytes

Versions: 142

Compression:

Stored size: 980 Bytes

Contents

module IndiferentHash

  def self.setup(hash)
    hash.extend IndiferentHash 
  end

  def merge(other)
    new = self.dup
    IndiferentHash.setup(new)
    other.each do |k,value|
      new.delete k
      new[k] = value
    end
    new
  end

  def []=(key,value)
    delete(key)
    super(key,value)
  end

  def [](key)
    res = super(key) 
    return res unless res.nil?

    case key
    when Symbol, Module
      super(key.to_s)
    when String
      super(key.to_sym)
    else
      super(key)
    end
  end

  def values_at(*key_list)
    key_list.inject([]){|acc,key| acc << self[key]}
  end

  def include?(key)
    case key
    when Symbol, Module
      super(key) || super(key.to_s)
    when String
      super(key) || super(key.to_sym)
    else
      super(key)
    end
  end

  def delete(key)
    case key
    when Symbol, Module
      super(key) || super(key.to_s)
    when String
      super(key) || super(key.to_sym)
    else
      super(key)
    end
  end
end

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
rbbt-util-5.19.3 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.2 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.1 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.0 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.18.1 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.18.0 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.89 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.88 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.87 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.86 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.85 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.84 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.83 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.82 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.81 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.80 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.78 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.77 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.76 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.75 lib/rbbt/util/misc/indiferent_hash.rb