diff options
author | Mike Dalessio <[email protected]> | 2024-01-30 08:05:51 -0500 |
---|---|---|
committer | git <[email protected]> | 2024-02-02 21:38:04 +0000 |
commit | 66a6f2b15a8827f830db7bf8cf8c8ebba79fa237 (patch) | |
tree | 0f9dcb74a43437012b18fc8e174b9fd3c1fd3bd7 /lib | |
parent | d2f004cf6a99564a59ed159c4963d199488665cd (diff) |
[rubygems/rubygems] feat: Gem::Requirement#initialize_copy deep-copies @requirements
to avoid accidentally mutating the original's state when doing:
```ruby
req2 = req.dup
req2.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/8e0c03144e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rubygems/requirement.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb index 4ebafb065f..02543cb14a 100644 --- a/lib/rubygems/requirement.rb +++ b/lib/rubygems/requirement.rb @@ -284,6 +284,11 @@ class Gem::Requirement def _tilde_requirements @_tilde_requirements ||= _sorted_requirements.select {|r| r.first == "~>" } end + + def initialize_copy(other) # :nodoc: + @requirements = other.requirements.dup + super + end end class Gem::Version |