Sha256: fecdfc804586a5c65508d807a4d1294ec0bc038277705bbdafcd583a11da61f9
Contents?: true
Size: 869 Bytes
Versions: 1
Compression:
Stored size: 869 Bytes
Contents
require 'ostruct' require 'nano/ostruct/__update__' class OpenStruct # Merge hash data creating a new OpenStruct object. # # o = OpenStruct.new # o.ostruct_merge { :a => 2 } # o.a #=> 2 # def __merge__( other ) o = dup o.__update__( other ) o end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TC_OpenStruct < Test::Unit::TestCase def test_merge_1 o = OpenStruct.new( { :a => 1 } ) h = { :b => 2 } q = o.__merge__( h ) assert_equal( 1, q.a ) assert_equal( 2, q.b ) end def test_merge_2 o1 = OpenStruct.new( { :a => 1 } ) o2 = OpenStruct.new( { :b => 2 } ) q = o1.__merge__( o2 ) assert_equal( 1, q.a ) assert_equal( 2, q.b ) end end =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.9.0 | lib/nano/ostruct/__merge__.rb |