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

ruby-changes:31324

From: marcandre <ko1@a...>
Date: Thu, 24 Oct 2013 00:14:02 +0900 (JST)
Subject: [ruby-changes:31324] marcandRe: r43403 (trunk): * lib/ostruct.rb (OpenStruct#delete): Use the converted argument.

marcandre	2013-10-24 00:13:38 +0900 (Thu, 24 Oct 2013)

  New Revision: 43403

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

  Log:
    * lib/ostruct.rb (OpenStruct#delete): Use the converted argument.
      Patch by Kenichi Kamiya. [Fixes GH-383]
    
    * test/ostruct/test_ostruct.rb: Added tests for above.

  Modified files:
    trunk/lib/ostruct.rb
    trunk/test/ostruct/test_ostruct.rb
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 43402)
+++ lib/ostruct.rb	(revision 43403)
@@ -220,7 +220,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L220
   #
   def delete_field(name)
     sym = name.to_sym
-    singleton_class.__send__(:remove_method, sym, "#{name}=")
+    singleton_class.__send__(:remove_method, sym, "#{sym}=")
     @table.delete sym
   end
 
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 43402)
+++ test/ostruct/test_ostruct.rb	(revision 43403)
@@ -68,6 +68,16 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L68
     assert_not_respond_to(o, :a, bug)
     assert_not_respond_to(o, :a=, bug)
     assert_equal(a, 'a')
+    s = Object.new
+    def s.to_sym
+      :foo
+    end
+    o[s] = true
+    assert_respond_to(o, :foo)
+    assert_respond_to(o, :foo=)
+    o.delete_field s
+    assert_not_respond_to(o, :foo)
+    assert_not_respond_to(o, :foo=)
   end
 
   def test_setter

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

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