Sha256: ba87e1d0015a0a9509afcac537386485fec4a889ab0638ef480203b582c72f00
Contents?: true
Size: 603 Bytes
Versions: 11
Compression:
Stored size: 603 Bytes
Contents
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
Version data entries
11 entries across 11 versions & 1 rubygems