Module: KUtil::Data::InstanceVariablesToH
- Defined in:
- lib/k_util/data/instance_variables_to_h.rb
Overview
Helper methods attached to the namespace for working with Data
Instance Method Summary collapse
Instance Method Details
#to_h(symbolize_keys: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/k_util/data/instance_variables_to_h.rb', line 9 def to_h(symbolize_keys: false) hash = {} instance_variables.each do |var| value = instance_variable_get(var) # TODO: Add deep support for symbolize_keys value = KUtil.data.to_hash(value) if KUtil.data.hash_convertible?(value) key = var.to_s.delete('@') key = key.to_sym if symbolize_keys hash[key] = value end hash end |