Module: Greeve::Helpers::AttributeToHash
Overview
Adds the `#to_h` method.
Instance Method Summary collapse
-
#to_h ⇒ Hash
The (private) `#_attributes` method must be implemented for this method to work.
Instance Method Details
#to_h ⇒ Hash
The (private) `#_attributes` method must be implemented for this method to work.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/greeve/helpers/attribute_to_hash.rb', line 9 def to_h _attributes .keys .map { |name| value = __send__(name) value = value.to_a if value.is_a?(Rowset) value = value.to_h if value.is_a?(Namespace) [name, value] } .to_h .reject { |k, v| v.nil? } end |