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.23 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.22 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.21 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.20 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.19 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.18 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.17 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.16 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.15 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.14 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.13 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.12 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.11 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.10 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.9 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.8 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.7 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.6 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.5 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.19.4 lib/rbbt/util/misc/indiferent_hash.rb