Module: Objectmancy::Hashable
- Defined in:
- lib/objectmancy/hashable.rb
Overview
Mixin for allowing your object to be converted into a Hash.
Class Method Summary collapse
-
.included(base) ⇒ Object
This is a little shady, but I’m not sure of a better way to do it.
Instance Method Summary collapse
-
#hashify ⇒ Hash
Turns the object into a Hash according to the rules defined with.
Class Method Details
.included(base) ⇒ Object
This is a little shady, but I’m not sure of a better way to do it. I gladly welcome suggestions.
30 31 32 |
# File 'lib/objectmancy/hashable.rb', line 30 def self.included(base) base.extend(CommonClassMethods) end |
Instance Method Details
#hashify ⇒ Hash
Turns the object into a Hash according to the rules defined with
37 38 39 40 41 |
# File 'lib/objectmancy/hashable.rb', line 37 def hashify _present_hashable_values.each_with_object({}) do |(attr, ), memo| memo[attr] = _hashify_value(send(attr), ) end end |