class OpenStruct

def to_h(&block)

RUBY_VERSION < 2.6 compatibility

# => {"country" => "AUSTRALIA", "capital" => "CANBERRA" }
data.to_h {|name, value| [name.to_s, value.upcase] }
data.to_h # => {:country => "Australia", :capital => "Canberra" }
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
require "ostruct"

the receiver will be used as pairs.
If a block is given, the results of the block on each pair of

each attribute (as symbols) and their corresponding values.
Converts the OpenStruct to a hash with keys representing

ostruct.to_h {|name, value| block } -> hash
ostruct.to_h -> hash
call-seq:
def to_h(&block)
  if block
    @table.to_h(&block)
  else
    @table.dup
  end
end