diff options
author | Akinori MUSHA <[email protected]> | 2020-09-20 23:23:13 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-12-04 19:23:35 +0900 |
commit | 46fc8d78a5d23d3c9a24e1bcc3c5cde4bce888de (patch) | |
tree | a1e52a035081028a81b8c4708c8a76a84a04f3af /lib/set.rb | |
parent | 0adc426ca5cf83e57f5e8433a2f7b55fb7a1fad6 (diff) |
[ruby/set] Resurrect support for Ruby 2.x
In Ruby 2.x, initialize_copy does not take a freeze option.
https://github.com/ruby/set/commit/3da6c309df
Diffstat (limited to 'lib/set.rb')
-rw-r--r-- | lib/set.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/set.rb b/lib/set.rb index d405d81178..844d52ed54 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -136,10 +136,18 @@ class Set @hash = orig.instance_variable_get(:@hash).dup end - # Clone internal hash. - def initialize_clone(orig, freeze: nil) - super - @hash = orig.instance_variable_get(:@hash).clone(freeze: freeze) + if Kernel.instance_method(:initialize_clone).arity != 1 + # Clone internal hash. + def initialize_clone(orig, **options) + super + @hash = orig.instance_variable_get(:@hash).clone(**options) + end + else + # Clone internal hash. + def initialize_clone(orig) + super + @hash = orig.instance_variable_get(:@hash).clone + end end def freeze # :nodoc: |