From a6456054aeb3ac859fd3f43b123b25673c266aa0 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 1 Apr 2017 10:30:48 +0000 Subject: [PATCH] ostruct.rb: improve fix for OpenStruct.allocate + #respond_to? * lib/ostruct.rb (OpenStruct#respond_to_missing?): this makes OpenStruct#respond_to? works on any OpenStruct instance, just like Kernel#respond_to? does, without workarounds. [ruby-core:80292] [Bug #13358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/ostruct.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 25ccac8dfa..2edb2edeb4 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -73,12 +73,6 @@ # of these properties compared to using a Hash or a Struct. # class OpenStruct - class << self # :nodoc: - def allocate - (x = super).instance_variable_set(:@table, {}) - x - end - end # # Creates a new OpenStruct object. By default, the resulting OpenStruct @@ -198,7 +192,7 @@ class OpenStruct def respond_to_missing?(mid, include_private = false) # :nodoc: mname = mid.to_s.chomp("=").to_sym - @table.key?(mname) || super + @table&.key?(mname) || super end def method_missing(mid, *args) # :nodoc: