Class: SnakyHash::Snake
- Inherits:
-
Module
- Object
- Module
- SnakyHash::Snake
- Defined in:
- lib/snaky_hash/snake.rb
Overview
Note:
Unlike Hashie::Mash, this implementation allows for both String and Symbol key types
Creates a module that provides key conversion functionality when included
Defined Under Namespace
Modules: SnakyModulizer
Instance Method Summary collapse
-
#included(base) ⇒ void
Includes appropriate conversion methods into the base class.
-
#initialize(key_type: :string, serializer: false) ⇒ Snake
constructor
Initialize a new Snake module.
Constructor Details
#initialize(key_type: :string, serializer: false) ⇒ Snake
Initialize a new Snake module
30 31 32 33 34 |
# File 'lib/snaky_hash/snake.rb', line 30 def initialize(key_type: :string, serializer: false) super() @key_type = key_type @serializer = serializer end |
Instance Method Details
#included(base) ⇒ void
This method returns an undefined value.
Includes appropriate conversion methods into the base class
40 41 42 43 44 45 46 |
# File 'lib/snaky_hash/snake.rb', line 40 def included(base) conversions_module = SnakyModulizer.to_mod(@key_type) base.include(conversions_module) if @serializer base.extend(SnakyHash::Serializer) end end |