Module: Google::Apis::Core::Hashable
- Defined in:
- lib/google/apis/core/hashable.rb
Overview
Adds to_hash to objects
Class Method Summary collapse
-
.process_value(val) ⇒ Hash
Recursively serialize an object.
Instance Method Summary collapse
-
#to_h ⇒ Hash
Convert object to hash representation.
Class Method Details
.process_value(val) ⇒ Hash
Recursively serialize an object
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_h ⇒ Hash
Convert object to hash representation
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 |