From 31e4300ea704365e4578841d99ffadb1dfe5fd24 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 30 Jan 2024 08:20:59 -0500 Subject: [rubygems/rubygems] feat: Gem::Specification#initialize_copy deep-copies requirements to avoid accidentally mutating the original's state when doing: ```ruby spec2 = spec.dup spec2.required_rubygems_version.concat([">= 3.3.22"]) ``` see https://github.com/rake-compiler/rake-compiler/pull/236 for a real-world use case that would be made simpler with this behavior. https://github.com/rubygems/rubygems/commit/c1d52389f0 --- lib/rubygems/specification.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index f7012f1efd..b47d7e8769 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -2075,7 +2075,8 @@ class Gem::Specification < Gem::BasicSpecification end ## - # Duplicates array_attributes from +other_spec+ so state isn't shared. + # Duplicates Array and Gem::Requirement attributes from +other_spec+ so state isn't shared. + # def initialize_copy(other_spec) self.class.array_attributes.each do |name| @@ -2097,6 +2098,9 @@ class Gem::Specification < Gem::BasicSpecification raise e end end + + @required_ruby_version = other_spec.required_ruby_version.dup + @required_rubygems_version = other_spec.required_rubygems_version.dup end def base_dir -- cgit v1.2.3