Sha256: 3c2c38e70cb60d9acaf93ba25f50c620c58c1d6f5e53ffc1035e5af317f080c5

Contents?: true

Size: 716 Bytes

Versions: 6

Compression:

Stored size: 716 Bytes

Contents

require 'ostruct'
require 'facets/core/hash/to_h'
require 'facets/core/ostruct/to_h'

class OpenStruct

  # Insert/update hash data on the fly.
  #
  #   o = OpenStruct.new
  #   o.ostruct_update { :a => 2 }
  #   o.a  #=> 2
  #
  def __update__( other )
    hash = other.to_h
    for k,v in hash
      @table[k.to_sym] = v
    end
  end

end


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

  require 'test/unit'

  class TCOpenStruct < Test::Unit::TestCase

    def test_update
      o = OpenStruct.new( { :a => 1 } )
      h = { :b => 2 }
      assert_nothing_raised { o.__update__( h ) }
      assert_equal( 2, o.b )
    end

  end

=end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-1.2.1 lib/facets/core/ostruct/__update__.rb
facets-1.3.0 lib/facets/core/ostruct/__update__.rb
facets-1.3.1 lib/facets/core/ostruct/__update__.rb
facets-1.3.2 lib/facets/core/ostruct/__update__.rb
facets-1.3.3 lib/facets/core/ostruct/__update__.rb
facets-1.4.0 lib/facets/core/ostruct/__update__.rb