summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-09-25 20:55:38 -0400
committerMarc-André Lafortune <github@marc-andre.ca>2020-09-30 18:11:24 -0400
commitdf4d08c44ac3e96336d29a360aafdc4b2a3e96fc (patch)
tree2a47ee14fc92eaee93bbaf6a82e573ab96f09f37 /lib
parentfb16c3dce2e629f9c443f9615df18cf2bbb3a077 (diff)
[ruby/ostruct] Avoid calling initialize
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3593
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 6f8f255511..31f46bba4d 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -121,11 +121,10 @@ class OpenStruct
# data # => #<OpenStruct country="Australia", capital="Canberra">
#
def initialize(hash=nil)
- @table = {}
if hash
- hash.each_pair do |k, v|
- set_ostruct_member_value!(k, v)
- end
+ update_to_values!(hash)
+ else
+ @table = {}
end
end
@@ -137,7 +136,14 @@ class OpenStruct
private def initialize_dup(orig) # :nodoc:
super
- initialize(@table)
+ update_to_values!(@table)
+ end
+
+ private def update_to_values!(hash) # :nodoc:
+ @table = {}
+ hash.each_pair do |k, v|
+ set_ostruct_member_value!(k, v)
+ end
end
#