1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/ostruct.rb: Fix case of frozen object with initializer.

Bug revealed by RubySpec [ruby-core:72639]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2016-01-01 17:27:38 +00:00
parent 428fe14f5e
commit 9543908c9f
3 changed files with 8 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Sat Jan 2 02:27:22 2016 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* 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@mbf.nifty.com> Fri Jan 1 22:01:52 2016 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
* NEWS: mention about CSV's liberal_parsing option. * NEWS: mention about CSV's liberal_parsing option.

View file

@ -195,7 +195,7 @@ class OpenStruct
modifiable[new_ostruct_member(mname)] = args[0] modifiable[new_ostruct_member(mname)] = args[0]
elsif len == 0 elsif len == 0
if @table.key?(mid) if @table.key?(mid)
new_ostruct_member(mid) new_ostruct_member(mid) unless frozen?
@table[mid] @table[mid]
end end
else else

View file

@ -61,13 +61,14 @@ class TC_OpenStruct < Test::Unit::TestCase
end end
def test_frozen def test_frozen
o = OpenStruct.new o = OpenStruct.new(foo: 42)
o.a = 'a' o.a = 'a'
o.freeze o.freeze
assert_raise(RuntimeError) {o.b = 'b'} assert_raise(RuntimeError) {o.b = 'b'}
assert_not_respond_to(o, :b) assert_not_respond_to(o, :b)
assert_raise(RuntimeError) {o.a = 'z'} assert_raise(RuntimeError) {o.a = 'z'}
assert_equal('a', o.a) assert_equal('a', o.a)
assert_equal(42, o.foo)
o = OpenStruct.new :a => 42 o = OpenStruct.new :a => 42
def o.frozen?; nil end def o.frozen?; nil end
o.freeze o.freeze