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