Class HashWithIndifferentAccess
In: activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
Parent: Hash

This class has dubious semantics and we only have it so that people can write params[:key] instead of params[‘key’]

Methods

[]=   convert_key   convert_value   default   delete   dup   fetch   key?   merge   new   stringify_keys!   symbolize_keys!   to_hash   update   values_at  

External Aliases

[]= -> regular_writer

Public Class methods

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 5
  def initialize(constructor = {})
    if constructor.is_a?(Hash)
      super()
      update(constructor)
    else
      super(constructor)
    end
  end

Public Instance methods

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 25
  def []=(key, value)
    regular_writer(convert_key(key), convert_value(value))
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 73
    def convert_key(key)
      key.kind_of?(Symbol) ? key.to_s : key
    end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 77
    def convert_value(value)
      case value
      when Hash
        value.with_indifferent_access
      when Array
        value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e }
      else
        value
      end
    end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 14
  def default(key = nil)
    if key.is_a?(Symbol) && include?(key = key.to_s)
      self[key]
    else
      super
    end
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 60
  def delete(key)
    super(convert_key(key))
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 52
  def dup
    HashWithIndifferentAccess.new(self)
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 44
  def fetch(key, *extras)
    super(convert_key(key), *extras)
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 36
  def key?(key)
    super(convert_key(key))
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 56
  def merge(hash)
    self.dup.update(hash)
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 64
  def stringify_keys!; self end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 65
  def symbolize_keys!; self end

Convert to a Hash with String keys.

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 68
  def to_hash
    Hash.new(default).merge(self)
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 29
  def update(other_hash)
    other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
    self
  end

[Source]

# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 48
  def values_at(*indices)
    indices.collect {|key| self[convert_key(key)]}
  end

[Validate]