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.17.32 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.31 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.30 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.29 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.28 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.27 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.26 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.25 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.24 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.23 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.22 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.21 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.20 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.19 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.18 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.17 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.16 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.15 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.14 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.17.13 lib/rbbt/util/misc/indiferent_hash.rb