module KUtil::Data::InstanceVariablesToH

Helper methods attached to the namespace for working with Data

Public Instance Methods

to_h() click to toggle source
# File lib/k_util/data/instance_variables_to_h.rb, line 8
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('@')] = value
  end
  hash
end