Module: ShipEngine::Utils::PrettyPrint

Defined in:
lib/shipengine/utils/pretty_print.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject

This will be used to add a to_hash method override to each class that includes the PrettyPrint module. This will return the class attributes and their values in a Hash.



20
21
22
23
24
25
26
# File 'lib/shipengine/utils/pretty_print.rb', line 20

def to_hash
  hash = {}
  instance_variables.each do |n|
    hash[n.to_s.delete('@')] = instance_variable_get(n)
  end
  hash
end

#to_sObject

This will be used to add a to_s method override to each class that includes the PrettyPrint module. This method returns a *JSON String* so one can easily inspect the contents of a given object.



12
13
14
# File 'lib/shipengine/utils/pretty_print.rb', line 12

def to_s
  JSON.pretty_generate(to_hash)
end