Module: Utils::Hash

Included in:
GbData, GbDataDescription
Defined in:
lib/ce-greenbutton/utils.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject

Converts instance variables of an object to a hash.

obj - the object to inspect

Returns a hash representing the instance variables of the given object.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ce-greenbutton/utils.rb', line 16

def to_hash
  if self.instance_variables.length > 0
    hash = {}
    self.instance_variables.each do |var|
      hash[var.to_s.delete('@')] = self.instance_variable_get(var)
    end
    hash
  else
    self
  end
end