aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/ostruct.rb6
-rw-r--r--test/ostruct/test_ostruct.rb4
3 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 7eae357464..222cb1cf17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 45ebb8083e..0ac6852433 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -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
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 5e0f4b2418..8adfd0159a 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -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