[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/tip4commit/tip4commit/master/features/support/to_ostruct.rb [Back]  [Original]

# frozen_string_literal: true

require 'ostruct'

class Hash
  def to_ostruct
    o = OpenStruct.new(self)
    each do |k, v|
      o.send(:"#{k}=", v.to_ostruct) if v.respond_to? :to_ostruct
    end
    o
  end
end

class Array
  def to_ostruct
    map do |item|
      if item.respond_to? :to_ostruct
        item.to_ostruct
      else
        item
      end
    end
  end
end

Web Proxy Viewer  |  New URL  |  Original Page