Module: KUtil::Data::InstanceVariablesToSymbolizedHash

Defined in:
lib/k_util/data/instance_variables_to_symbolized_hash.rb

Overview

Helper methods attached to the namespace for working with Data

Instance Method Summary collapse

Instance Method Details

#to_hObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/k_util/data/instance_variables_to_symbolized_hash.rb', line 9

def to_h
  hash = {}
  instance_variables.each do |var|
    value = instance_variable_get(var)

    value = KUtil.data.to_hash(value) if KUtil.data.hash_convertible?(value)

    hash[var.to_s.delete('@').to_sym] = value
  end
  hash
end