mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
8dfd1e71fc
commit
a6456054ae
1 changed files with 1 additions and 7 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue