aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-09-14 15:15:28 -0400
committerMarc-André Lafortune <github@marc-andre.ca>2020-09-14 16:10:37 -0400
commit60f5d384820a4b07f739d32c2233b1dbc74a726a (patch)
treef2c03842f3ec17f0ec50c4904e5d55f958c0b1d6 /lib
parent125605abd949b23a8a95e1cc95f7d435efc17290 (diff)
downloadruby-60f5d384820a4b07f739d32c2233b1dbc74a726a.tar.gz
[ruby/ostruct] Fix dup/clone
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index f403f63bdb..6f8f255511 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -130,10 +130,14 @@ class OpenStruct
end
# Duplicates an OpenStruct object's Hash table.
- def initialize_copy(orig) # :nodoc:
- orig.table.each_key{|key| new_ostruct_member!(key)}
+ private def initialize_clone(orig) # :nodoc:
+ super # clones the singleton class for us
+ @table = @table.dup unless @table.frozen?
+ end
+
+ private def initialize_dup(orig) # :nodoc:
super
- @table = @table.dup
+ initialize(@table)
end
#