aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-09-08 16:30:02 -0400
committerMarc-Andre Lafortune <github@marc-andre.ca>2020-09-14 12:46:47 -0400
commit8eefa8f3736cd5dbf7256f571b368198102f11cc (patch)
treee1205bfed121928c06167c99cbc900208e30da8e /lib
parentebb8de730269a8c18a553e3dea7a7603b13d2328 (diff)
downloadruby-8eefa8f3736cd5dbf7256f571b368198102f11cc.tar.gz
[ruby/ostruct] Allow overriding public methods
[Fixes https://bugs.ruby-lang.org/issues/15409]
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 18850bfafb..5f3d301ce0 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -100,9 +100,9 @@ class OpenStruct
# Duplicates an OpenStruct object's Hash table.
def initialize_copy(orig) # :nodoc:
+ orig.table.each_key{|key| new_ostruct_member!(key)}
super
@table = @table.dup
- @table.each_key{|key| new_ostruct_member!(key)}
end
#
@@ -159,8 +159,8 @@ class OpenStruct
# Provides marshalling support for use by the Marshal library.
#
def marshal_load(x)
+ x.each_key{|key| new_ostruct_member!(key)}
@table = x
- @table.each_key{|key| new_ostruct_member!(key)}
end
#
@@ -169,7 +169,7 @@ class OpenStruct
# define_singleton_method for both the getter method and the setter method.
#
def new_ostruct_member!(name) # :nodoc:
- unless respond_to?(name)
+ unless @table.key?(name)
define_singleton_method(name) { @table[name] }
define_singleton_method("#{name}=") {|x| @table[name] = x}
end