Module: Google::Apis::Core::Hashable

Defined in:
lib/google/apis/core/hashable.rb

Overview

Adds to_hash to objects

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process_value(val) ⇒ Hash

Recursively serialize an object

Parameters:

  • val (Object)

Returns:

  • (Hash)


31
32
33
34
35
36
37
38
39
40
# File 'lib/google/apis/core/hashable.rb', line 31

def self.process_value(val)
  case val
  when Hash
    Hash[val.map {|k, v| [k.to_sym, Hashable.process_value(v)] }]
  when Array
    val.map{ |v| Hashable.process_value(v) }
  else
    val.respond_to?(:to_h) ? val.to_h : val
  end
end

Instance Method Details

#to_hHash

Convert object to hash representation

Returns:

  • (Hash)


23
24
25
# File 'lib/google/apis/core/hashable.rb', line 23

def to_h
  Hash[instance_variables.map { |k| [k[1..-1].to_sym, Hashable.process_value(instance_variable_get(k))] }]
end