class SnakyHash::Snake

Creates a module that provides key conversion functionality when included

@note Unlike Hashie::Mash, this implementation allows for both String and Symbol key types

Public Class Methods

new(key_type: :string, serializer: false) click to toggle source

Initialize a new Snake module

@param key_type [Symbol] the type to convert keys to (:string or :symbol) @param serializer [Boolean] whether to include serialization capabilities @raise [ArgumentError] if key_type is not :string or :symbol

Calls superclass method
   # File lib/snaky_hash/snake.rb
30 def initialize(key_type: :string, serializer: false)
31   super()
32   @key_type = key_type
33   @serializer = serializer
34 end

Public Instance Methods

included(base) click to toggle source

Includes appropriate conversion methods into the base class

@param base [Class] the class including this module @return [void]

   # File lib/snaky_hash/snake.rb
40 def included(base)
41   conversions_module = SnakyModulizer.to_mod(@key_type)
42   base.include(conversions_module)
43   if @serializer
44     base.extend(SnakyHash::Serializer)
45   end
46 end