require 'ostruct'

class Hash

  # Turns a hash into a generic object using an OpenStruct.
  #
  #   o = { 'a' => 1 }.to_ostruct
  #   o.a  #=> 1
  #
  def to_ostruct
    OpenStruct.new( self )
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCHash < Test::Unit::TestCase

    def test_to_ostruct
      a = { :a => 1, :b => 2, :c => 3 }
      ao = a.to_ostruct
      assert_equal( a[:a], ao.a )
      assert_equal( a[:b], ao.b )
      assert_equal( a[:c], ao.c )
    end

  end

=end
