Module: Lazier::Hash

Extended by:
ActiveSupport::Concern
Defined in:
lib/lazier/hash.rb

Overview

Extensions for Hash objects.

Instance Method Summary collapse

Instance Method Details

#ensure_access(access) ⇒ Object

Makes sure that the keys of the hash are accessible in the desired way.

Parameters:

  • access (Symbol|NilClass)

    The requested access for the keys. Can be :strings, :symbols or :indifferent. If nil the keys are not modified.



15
16
17
18
# File 'lib/lazier/hash.rb', line 15

def ensure_access(access)
  method = {strings: :stringify_keys, symbols: :symbolize_keys, indifferent: :with_indifferent_access}.fetch(access, nil)
  method ? send(method) : self
end