Class: Isomorphic::HashWithIndifferentAccess

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/isomorphic/hash_with_indifferent_access.rb

Overview

Implements a hash where keys :foo, “foo” and Foo are considered to be the same.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inflector, constructor = {}) ⇒ HashWithIndifferentAccess

Default constructor.

Parameters:

Raises:



15
16
17
18
19
# File 'lib/isomorphic/hash_with_indifferent_access.rb', line 15

def initialize(inflector, constructor = {})
  @inflector = inflector

  super(constructor)
end

Instance Attribute Details

#inflectorObject (readonly)

Returns the value of attribute inflector.



8
9
10
# File 'lib/isomorphic/hash_with_indifferent_access.rb', line 8

def inflector
  @inflector
end

Instance Method Details

#[](key) ⇒ Object

Same as Hash#[] where the key passed as argument can be either a string, a symbol or a class.

Parameters:

  • key (Object)

    the key

Returns:

  • (Object)

    the value

Raises:



26
27
28
# File 'lib/isomorphic/hash_with_indifferent_access.rb', line 26

def [](key)
  super(convert_key(key))
end

#assoc(key) ⇒ Array<Object>?

Same as Hash#assoc where the key passed as argument can be either a string, a symbol or a class.

Parameters:

  • key (Object)

    the key

Returns:

  • (Array<Object>, nil)

    the key-value pair or nil if the key is not present

Raises:



35
36
37
# File 'lib/isomorphic/hash_with_indifferent_access.rb', line 35

def assoc(key)
  super(convert_key(key))
end

#dig(*args) ⇒ Object?

Same as Hash#dig where the key passed as argument can be either a string, a symbol or a class.

Parameters:

  • args (Array<Object>)

    the keys

Returns:

  • (Object, nil)

    the value or nil

Raises:



45
46
47
48
# File 'lib/isomorphic/hash_with_indifferent_access.rb', line 45

def dig(*args)
  args[0] = convert_key(args[0]) if args.size > 0
  super(*args)
end