ruby-changes:41335
From: marcandre <ko1@a...>
Date: Sat, 2 Jan 2016 02:27:51 +0900 (JST)
Subject: [ruby-changes:41335] marcandRe: r53407 (trunk): * lib/ostruct.rb: Fix case of frozen object with initializer.
marcandre 2016-01-01 17:27:38 +0000 (Fri, 01 Jan 2016) New Revision: 53407 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53407 Log: * lib/ostruct.rb: Fix case of frozen object with initializer. Bug revealed by RubySpec [ruby-core:72639] Modified files: trunk/ChangeLog trunk/lib/ostruct.rb trunk/test/ostruct/test_ostruct.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 53406) +++ ChangeLog (revision 53407) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jan 2 02:27:22 2016 Marc-Andre Lafortune <ruby-core@m...> + + * lib/ostruct.rb: Fix case of frozen object with initializer. + Bug revealed by RubySpec [ruby-core:72639] + Fri Jan 1 22:01:52 2016 Kazuhiro NISHIYAMA <zn@m...> * NEWS: mention about CSV's liberal_parsing option. Index: test/ostruct/test_ostruct.rb =================================================================== --- test/ostruct/test_ostruct.rb (revision 53406) +++ test/ostruct/test_ostruct.rb (revision 53407) @@ -61,13 +61,14 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L61 end def test_frozen - o = OpenStruct.new + o = OpenStruct.new(foo: 42) o.a = 'a' o.freeze assert_raise(RuntimeError) {o.b = 'b'} assert_not_respond_to(o, :b) assert_raise(RuntimeError) {o.a = 'z'} assert_equal('a', o.a) + assert_equal(42, o.foo) o = OpenStruct.new :a => 42 def o.frozen?; nil end o.freeze Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 53406) +++ lib/ostruct.rb (revision 53407) @@ -195,7 +195,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L195 modifiable[new_ostruct_member(mname)] = args[0] elsif len == 0 if @table.key?(mid) - new_ostruct_member(mid) + new_ostruct_member(mid) unless frozen? @table[mid] end else -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/