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.13.31 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.30 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.29 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.28 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.27 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.26 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.25 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.24 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.23 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.22 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.21 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.20 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.19 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.18 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.17 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.16 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.15 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.14 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.13 lib/rbbt/util/misc/indiferent_hash.rb
rbbt-util-5.13.12 lib/rbbt/util/misc/indiferent_hash.rb