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

* lib/ostruct.rb (modifiable): check if really frozen.

[ruby-core:22559]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-02-27 05:23:10 +00:00
parent 770f854176
commit 1942710d42
3 changed files with 13 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Fri Feb 27 14:23:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/ostruct.rb (modifiable): check if really frozen.
[ruby-core:22559]
Thu Feb 26 23:14:46 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/lib/socket.rb (BasicSocket#connect_address): new method.

View file

@ -68,8 +68,10 @@ class OpenStruct
end
def modifiable
if self.frozen?
raise TypeError, "can't modify frozen #{self.class}", caller(2)
begin
@modifiable = true
rescue
raise TypeError, "can't modify frozen #{self.class}", caller(3)
end
@table
end

View file

@ -43,5 +43,9 @@ class TC_OpenStruct < Test::Unit::TestCase
assert_not_respond_to(o, :b)
assert_raise(TypeError) {o.a = 'z'}
assert_equal('a', o.a)
o = OpenStruct.new :a => 42
def o.frozen?; nil end
o.freeze
assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764}
end
end