Module: Hashie::Extensions::MethodOverridingInitializer

Includes:
RedefineMethod
Defined in:
lib/hashie/extensions/method_access.rb

Overview

MethodOverridingInitializer allows you to override default hash methods when passing in values from an existing hash. The overriden methods are aliased with two leading underscores.

Examples:

class MyHash < Hash
  include Hashie::Extensions::MethodOverridingInitializer
end

h = MyHash.new(zip: 'a-dee-doo-dah')
h.zip # => 'a-dee-doo-dah'
h.__zip # => [[['zip', 'a-dee-doo-dah']]]

Instance Method Summary collapse

Instance Method Details

#initialize(hash = {}) ⇒ Object



258
259
260
261
262
263
264
# File 'lib/hashie/extensions/method_access.rb', line 258

def initialize(hash = {})
  hash.each do |key, value|
    skey = key.to_s
    redefine_method(skey) if method?(skey)
    self[skey] = value
  end
end