diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-09-25 20:55:38 -0400 |
---|---|---|
committer | Marc-André Lafortune <github@marc-andre.ca> | 2020-09-30 18:11:24 -0400 |
commit | df4d08c44ac3e96336d29a360aafdc4b2a3e96fc (patch) | |
tree | 2a47ee14fc92eaee93bbaf6a82e573ab96f09f37 /lib/ostruct.rb | |
parent | fb16c3dce2e629f9c443f9615df18cf2bbb3a077 (diff) |
[ruby/ostruct] Avoid calling initialize
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3593
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 16 |
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 # |