* lib/ostruct.rb (OpenStruct#delete_field): also undefine
accessor methods. [ruby-core:33010] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
742d440cba
commit
4ec86dcc57
@ -1,3 +1,8 @@
|
|||||||
|
Wed Nov 3 14:17:18 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/ostruct.rb (OpenStruct#delete_field): also undefine
|
||||||
|
accessor methods. [ruby-core:33010]
|
||||||
|
|
||||||
Wed Nov 3 14:13:46 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Nov 3 14:13:46 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* string.c (rb_enc_cr_str_buf_cat): concatenation of valid
|
* string.c (rb_enc_cr_str_buf_cat): concatenation of valid
|
||||||
|
@ -107,7 +107,9 @@ class OpenStruct
|
|||||||
# Remove the named field from the object.
|
# Remove the named field from the object.
|
||||||
#
|
#
|
||||||
def delete_field(name)
|
def delete_field(name)
|
||||||
@table.delete name.to_sym
|
sym = name.to_sym
|
||||||
|
@table.delete sym
|
||||||
|
singleton_class.__send__(:remove_method, sym, "#{name}=")
|
||||||
end
|
end
|
||||||
|
|
||||||
InspectKey = :__inspect_key__ # :nodoc:
|
InspectKey = :__inspect_key__ # :nodoc:
|
||||||
|
@ -48,4 +48,17 @@ class TC_OpenStruct < Test::Unit::TestCase
|
|||||||
o.freeze
|
o.freeze
|
||||||
assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764}
|
assert_raise(TypeError, '[ruby-core:22559]') {o.a = 1764}
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user