Sha256: 0733ccf7b7fb9061a0d968e722724a6833189165b8c43773a10908048d3c0536

Contents?: true

Size: 686 Bytes

Versions: 20

Compression:

Stored size: 686 Bytes

Contents

require 'ostruct'

class OpenStruct

  # Set a value in the OpenStruct by key, like a Hash.
  #
  #   o = OpenStruct.new
  #   o['t'] = 4
  #   o.t  #=> 4 
  #
  def []=(key,val)
    raise TypeError, "can't modify frozen #{self.class}", caller(1) if self.frozen?
    key = key.to_sym unless key.is_a?(Symbol)
    @table[key]=val
  end

end



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

  require 'test/unit'

  class TCOpenStruct < Test::Unit::TestCase

    def test_op_store
      o = OpenStruct.new( { :a => 1 } )
      assert_nothing_raised { o[:b] = 2 }
      assert_equal( 2, o.b )
    end

  end

=end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
facets-1.0.3 packages/core/lib/facet/ostruct/op_store.rb
facets-0.9.0 lib/nano/ostruct/op_store.rb
facets-1.0.0 lib/facet/ostruct/op_store.rb
facets-1.3.0 lib/facets/core/ostruct/op_store.rb
facets-1.1.0 lib/facet/ostruct/op_store.rb
facets-1.2.0 lib/facets/core/ostruct/op_store.rb
facets-1.2.1 lib/facets/core/ostruct/op_store.rb
facets-1.3.2 lib/facets/core/ostruct/op_store.rb
facets-1.3.1 lib/facets/core/ostruct/op_store.rb
facets-1.3.3 lib/facets/core/ostruct/op_store.rb
facets-1.4.2 lib/facets/core/ostruct/op_store.rb
facets-1.4.0 lib/facets/core/ostruct/op_store.rb
facets-1.4.1 lib/facets/core/ostruct/op_store.rb
facets-1.4.3 lib/facets/core/ostruct/op_store.rb
facets-1.4.4 lib/facets/core/ostruct/op_store.rb
facets-1.4.5 lib/facets/core/ostruct/op_store.rb
facets-1.7.0 lib/facets/core/ostruct/op_store.rb
facets-1.7.30 lib/facets/core/ostruct/op_store.rb
facets-1.7.38 lib/facets/core/ostruct/op_store.rb
facets-1.7.46 lib/facets/core/ostruct/op_store.rb