[前][次][番号順一覧][スレッド一覧]

ruby-changes:17668

From: nobu <ko1@a...>
Date: Wed, 3 Nov 2010 14:21:49 +0900 (JST)
Subject: [ruby-changes:17668] Ruby:r29677 (trunk): * lib/ostruct.rb (OpenStruct#delete_field): also undefine

nobu	2010-11-03 14:17:25 +0900 (Wed, 03 Nov 2010)

  New Revision: 29677

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29677

  Log:
    * lib/ostruct.rb (OpenStruct#delete_field): also undefine
      accessor methods.  [ruby-core:33010]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
    trunk/test/ostruct/test_ostruct.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29676)
+++ ChangeLog	(revision 29677)
@@ -1,3 +1,8 @@
+Wed Nov  3 14:17:18 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/ostruct.rb (OpenStruct#delete_field): also undefine
+	  accessor methods.  [ruby-core:33010]
+
 Wed Nov  3 14:13:46 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_enc_cr_str_buf_cat): concatenation of valid
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 29676)
+++ lib/ostruct.rb	(revision 29677)
@@ -107,7 +107,9 @@
   # Remove the named field from the object.
   #
   def delete_field(name)
-    @table.delete name.to_sym
+    sym = name.to_sym
+    @table.delete sym
+    singleton_class.__send__(:remove_method, sym, "#{name}=")
   end
 
   InspectKey = :__inspect_key__ # :nodoc:
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 29676)
+++ test/ostruct/test_ostruct.rb	(revision 29677)
@@ -48,4 +48,17 @@
     o.freeze
     assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764}
   end
+
+  def test_delete_field
+    bug = '[ruby-core:33010]'
+    o = OpenStruct.new
+    assert_not_respond_to(o, :a)
+    assert_not_respond_to(o, :a=)
+    o.a = 'a'
+    assert_respond_to(o, :a)
+    assert_respond_to(o, :a=)
+    o.delete_field :a
+    assert_not_respond_to(o, :a, bug)
+    assert_not_respond_to(o, :a=, bug)
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]