Module: Hashie::Extensions::Mash::KeepOriginalKeys

Defined in:
lib/hashie/extensions/mash/keep_original_keys.rb

Overview

Overrides the indifferent access of a Mash to keep keys in the original format given to the Mash.

Examples:

class KeepingMash < Hashie::Mash
  include Hashie::Extensions::Mash::KeepOriginalKeys
end

mash = KeepingMash.new(:symbol_key => :symbol, 'string_key' => 'string')
mash.to_hash  #=> { :symbol_key => :symbol, 'string_key' => 'string' }
mash['string_key'] == mash[:string_key]  #=> true
mash[:symbol_key] == mash['symbol_key']  #=> true

Class Method Summary collapse

Class Method Details

.included(descendant) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/hashie/extensions/mash/keep_original_keys.rb', line 17

def self.included(descendant)
  error_message = "#{descendant} is not a kind of Hashie::Mash"
  raise ArgumentError, error_message unless descendant <= Hashie::Mash
end