Sha256: 49482340d7538029c032c9f430596ed62128dd7640a8475c762460e065a3ed7a

Contents?: true

Size: 915 Bytes

Versions: 61

Compression:

Stored size: 915 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)
    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

61 entries across 61 versions & 1 rubygems

Version Path
rbbt-util-5.14.14 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.12 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.11 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.10 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.9 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.8 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.7 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.6 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.5 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.4 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.3 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.2 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.1 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.14.0 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.37 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.36 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.35 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.34 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.33 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.32 lib/rbbt/util/misc/indiferent_hash.rb