module Polyfill::V2_6::OpenStruct

Public Instance Methods

to_h() click to toggle source
Calls superclass method
# File lib/polyfill/v2_6/open_struct.rb, line 6
def to_h
  return super unless block_given?

  block = ::Proc.new

  pairs = each_pair.map do |k, v|
    pair = block.call(k, v)

    unless pair.respond_to?(:to_ary)
      raise TypeError, "wrong element type #{pair.class} (expected array)"
    end

    pair = pair.to_ary

    unless pair.length == 2
      raise ArgumentError, "element has wrong array length (expected 2, was #{pair.length})"
    end

    pair
  end

  pairs.to_h
end