Skip to content

Commit 4d41d46

Browse files
committed
[GR-20126] Implement Numeric#clone method to return self.
PullRequest: truffleruby/1194
2 parents d83552e + 502e942 commit 4d41d46

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Bug fixes:
4646
* Fixed issue with `SystemCallError.new` setting a backtrace.
4747
* Fixed `BigDecimal#to_s` formatting issue (#1711).
4848
* Run `END` keyword block only once at exit.
49+
* Implement Numeric#clone method to return self.
4950

5051
Compatibility:
5152

spec/tags/core/kernel/clone_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ fails:Kernel#clone returns true for TrueClass
33
fails:Kernel#clone returns false for FalseClass
44
fails:Kernel#clone returns the same Integer for Integer
55
fails:Kernel#clone returns the same Symbol for Symbol
6-
fails:Kernel#clone returns self for Complex
7-
fails:Kernel#clone returns self for Rational

src/main/ruby/truffleruby/core/numeric.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
class Numeric
3030
include Comparable
3131

32-
# Always raises TypeError, as dup'ing Numerics is not allowed.
33-
def initialize_copy(other)
34-
raise TypeError, "copy of #{self.class} is not allowed"
32+
def clone(freeze: true)
33+
unless freeze
34+
raise ArgumentError, "can't unfreeze #{self.class.name}"
35+
end
36+
self
3537
end
3638

3739
def +@

0 commit comments

Comments
 (0)