module OpenstructUtils
Constants
- VERSION
Public Class Methods
openstruct_to_hash(struct)
click to toggle source
# File lib/openstruct_utils.rb, line 11 def self.openstruct_to_hash struct hash = struct.marshal_dump recurisive_transform_openstruct_to_hash hash end
openstruct_to_json(struct)
click to toggle source
# File lib/openstruct_utils.rb, line 6 def self.openstruct_to_json struct JSON.pretty_generate openstruct_to_hash struct end
recurisive_transform_openstruct_to_hash(hash)
click to toggle source
# File lib/openstruct_utils.rb, line 17 def self.recurisive_transform_openstruct_to_hash hash hash.each_pair do |key, val| if val.instance_of?(Hash) hash[key] = recurisive_transform_openstruct_to_hash val elsif val.instance_of?(Array) hash[key] = val.map do |arr| if arr.instance_of?(OpenStruct) recurisive_transform_openstruct_to_hash arr.marshal_dump elsif arr.instance_of?(Hash) recurisive_transform_openstruct_to_hash arr else arr end end elsif val.instance_of?(OpenStruct) hash[key] = recurisive_transform_openstruct_to_hash val.marshal_dump end end hash end