diff options
| author | Mike Dalessio <mike.dalessio@gmail.com> | 2024-01-30 08:20:59 -0500 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-02 21:38:04 +0000 |
| commit | 31e4300ea704365e4578841d99ffadb1dfe5fd24 (patch) | |
| tree | 6e904266f8d48cb9f872bf637d7b4e18fb06b1f2 /lib | |
| parent | 66a6f2b15a8827f830db7bf8cf8c8ebba79fa237 (diff) | |
[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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/rubygems/specification.rb | 6 |
1 files changed, 5 insertions, 1 deletions
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 |
