зеркало из https://github.com/github/ruby.git
[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
This commit is contained in:
Родитель
0adc426ca5
Коммит
46fc8d78a5
12
lib/set.rb
12
lib/set.rb
|
@ -136,10 +136,18 @@ class Set
|
|||
@hash = orig.instance_variable_get(:@hash).dup
|
||||
end
|
||||
|
||||
if Kernel.instance_method(:initialize_clone).arity != 1
|
||||
# Clone internal hash.
|
||||
def initialize_clone(orig, freeze: nil)
|
||||
def initialize_clone(orig, **options)
|
||||
super
|
||||
@hash = orig.instance_variable_get(:@hash).clone(freeze: freeze)
|
||||
@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:
|
||||
|
|
|
@ -739,7 +739,7 @@ class TC_Set < Test::Unit::TestCase
|
|||
set2.add 5
|
||||
assert_equal Set[1,2,3,5], set2
|
||||
assert_equal Set[1,2,3], set1
|
||||
end
|
||||
end if Kernel.instance_method(:initialize_clone).arity != 1
|
||||
|
||||
def test_inspect
|
||||
set1 = Set[1, 2]
|
||||
|
|
Загрузка…
Ссылка в новой задаче