Skip to content

Commit 3da6c30

Browse files
committed
Resurrect support for Ruby 2.x
In Ruby 2.x, initialize_copy does not take a freeze option.
1 parent a45625e commit 3da6c30

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/set.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,18 @@ def initialize_dup(orig)
136136
@hash = orig.instance_variable_get(:@hash).dup
137137
end
138138

139-
# Clone internal hash.
140-
def initialize_clone(orig, freeze: nil)
141-
super
142-
@hash = orig.instance_variable_get(:@hash).clone(freeze: freeze)
139+
if Kernel.instance_method(:initialize_clone).arity != 1
140+
# Clone internal hash.
141+
def initialize_clone(orig, **options)
142+
super
143+
@hash = orig.instance_variable_get(:@hash).clone(**options)
144+
end
145+
else
146+
# Clone internal hash.
147+
def initialize_clone(orig)
148+
super
149+
@hash = orig.instance_variable_get(:@hash).clone
150+
end
143151
end
144152

145153
def freeze # :nodoc:

test/test_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def test_freeze_clone_false
739739
set2.add 5
740740
assert_equal Set[1,2,3,5], set2
741741
assert_equal Set[1,2,3], set1
742-
end
742+
end if Kernel.instance_method(:initialize_clone).arity != 1
743743

744744
def test_inspect
745745
set1 = Set[1, 2]

0 commit comments

Comments
 (0)