summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ostruct.rb2
-rw-r--r--test/ostruct/test_ostruct.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 6b60bdf3fe..3c14454437 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -220,7 +220,7 @@ class OpenStruct
#
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
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index a472509b88..3c1d574e32 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -68,6 +68,16 @@ class TC_OpenStruct < Test::Unit::TestCase
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