ruby-changes:39866
From: nobu <ko1@a...>
Date: Sun, 27 Sep 2015 08:16:59 +0900 (JST)
Subject: [ruby-changes:39866] nobu:r51947 (trunk): ostruct.rb: fix NameError
nobu 2015-09-27 08:16:37 +0900 (Sun, 27 Sep 2015) New Revision: 51947 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51947 Log: ostruct.rb: fix NameError * lib/ostruct.rb (delete_field): do not raise NameError for existing keys. [Fix GH-1033] Modified files: trunk/ChangeLog trunk/lib/ostruct.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51946) +++ ChangeLog (revision 51947) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Sep 27 08:16:35 2015 Nobuyoshi Nakada <nobu@r...> + + * lib/ostruct.rb (delete_field): do not raise NameError for + existing keys. [Fix GH-1033] + +Sun Sep 27 08:16:20 2015 Nobuyoshi Nakada <nobu@r...> + + * lib/ostruct.rb (delete_field): do not raise NameError for + existing keys. [Fix GH-1033] + Sun Sep 27 00:34:31 2015 Zachary Scott <zzak@r...> * lib/ostruct.rb: Move method definitions for getter/setter to be lazy Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 51946) +++ lib/ostruct.rb (revision 51947) @@ -220,8 +220,13 @@ 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, "#{sym}=") - @table.delete sym + begin + singleton_class.__send__(:remove_method, sym, "#{sym}=") + rescue NameError + end + @table.delete(sym) do + raise NameError.new("no field `#{sym}' in #{self}", sym) + end end InspectKey = :__inspect_key__ # :nodoc: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/