зеркало из 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
16
lib/set.rb
16
lib/set.rb
|
@ -136,10 +136,18 @@ class Set
|
||||||
@hash = orig.instance_variable_get(:@hash).dup
|
@hash = orig.instance_variable_get(:@hash).dup
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clone internal hash.
|
if Kernel.instance_method(:initialize_clone).arity != 1
|
||||||
def initialize_clone(orig, freeze: nil)
|
# Clone internal hash.
|
||||||
super
|
def initialize_clone(orig, **options)
|
||||||
@hash = orig.instance_variable_get(:@hash).clone(freeze: freeze)
|
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
|
end
|
||||||
|
|
||||||
def freeze # :nodoc:
|
def freeze # :nodoc:
|
||||||
|
|
|
@ -739,7 +739,7 @@ class TC_Set < Test::Unit::TestCase
|
||||||
set2.add 5
|
set2.add 5
|
||||||
assert_equal Set[1,2,3,5], set2
|
assert_equal Set[1,2,3,5], set2
|
||||||
assert_equal Set[1,2,3], set1
|
assert_equal Set[1,2,3], set1
|
||||||
end
|
end if Kernel.instance_method(:initialize_clone).arity != 1
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
set1 = Set[1, 2]
|
set1 = Set[1, 2]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче