Module: Hashing::Hasherizer
- Defined in:
- lib/hashing.rb
Overview
Define the class methods that should be available in a ‘hasherized ®’ class (a class that include ‘Hashing`).
Instance Method Summary collapse
-
#from_hash(pairs) ⇒ Object
Receives a ‘Hash` and uses the strategy configured by `.loading` to (re)create an instance of the ’hasherized ®‘ class.
-
#ivars ⇒ Array
provides access to the current configuration on what ‘ivars` should be used to generate a `Hash` representation of instances of the client class.
Instance Method Details
#from_hash(pairs) ⇒ Object
Receives a ‘Hash` and uses the strategy configured by `.loading` to (re)create an instance of the ’hasherized ®‘ class.
120 121 122 123 124 125 126 127 |
# File 'lib/hashing.rb', line 120 def from_hash(pairs) = pairs.delete(:__hashing__) || {} hash_to_load = pairs.map do |ivar_name, value| ivar = ivar_by_name ivar_name.to_sym [ivar.to_sym, ivar.from_hash(value, )] end strategy.call Hash[hash_to_load] end |
#ivars ⇒ Array
provides access to the current configuration on what ‘ivars` should be used to generate a `Hash` representation of instances of the client class.
111 112 113 |
# File 'lib/hashing.rb', line 111 def ivars @ivars ||= [] end |