Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
namara / lib / helpers / object_to_hash.rb
Size: Mime:
module ObjectToHash
  module_function

  def to_hash_array(array_object)
    hash_arrays = []

    array_object.each do |object|
      hash_arrays.push(OpenStruct.new(object.to_h))
    end

    hash_arrays
  end

  def deep_ostruct(obj)
    case obj
    when Hash
      root = OpenStruct.new(obj)
      obj.each_with_object(root) do |(k,v), o|
        o.send("#{k}=", deep_ostruct(v))
      end
      root
    when Array
      obj.map do |v|
        deep_ostruct(v)
      end
    else
      obj
    end
  end

end