Skip to content

Commit f021ad9

Browse files
committed
Fix BigDecimal#clone to return the receiver rather than a new object.
1 parent 0299e6a commit f021ad9

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Bug fixes:
44

5-
* Fixed `BigDecimal#dup` so it now just returns the receiver, per Ruby 2.5+ semantics (#1680).
5+
* Fixed `BigDecimal#{clone,dup}` so it now just returns the receiver, per Ruby 2.5+ semantics (#1680).
66
* Fixed creating `BigDecimal` instances from non-finite `Float` values (#1685).
77
* Fixed `BigDecimal#inspect` output for non-finite values (e.g, NaN or -Infinity) (#1683).
88
* Implemented `rb_eval_string_protect`.

lib/truffle/bigdecimal.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ def self.limit(limit = nil)
7979
end
8080
end
8181

82-
def dup
82+
def clone
8383
self
8484
end
85+
alias_method :dup, :clone
8586

8687
# TODO (pitr 20-jun-2015): remove when lazy setup is added
8788
def self.name
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require_relative '../../spec_helper'
2+
require_relative 'shared/clone'
3+
4+
describe "BigDecimal#dup" do
5+
it_behaves_like :bigdecimal_clone, :clone
6+
end
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
require_relative '../../spec_helper'
2-
require 'bigdecimal'
2+
require_relative 'shared/clone'
33

44
describe "BigDecimal#dup" do
5-
before :each do
6-
@obj = BigDecimal("1.2345")
7-
end
8-
9-
ruby_version_is "" ... "2.5" do
10-
it "copies the BigDecimal's value to a newly allocated object" do
11-
copy = @obj.dup
12-
13-
copy.should_not equal(@obj)
14-
copy.should == @obj
15-
end
16-
end
17-
18-
ruby_version_is "2.5" do
19-
it "returns self" do
20-
@obj.dup.should equal(@obj)
21-
end
22-
end
5+
it_behaves_like :bigdecimal_clone, :dup
236
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'bigdecimal'
2+
3+
describe :bigdecimal_clone, shared: true do
4+
before :each do
5+
@obj = BigDecimal("1.2345")
6+
end
7+
8+
ruby_version_is "" ... "2.5" do
9+
it "copies the BigDecimal's value to a newly allocated object" do
10+
copy = @obj.public_send(@method)
11+
12+
copy.should_not equal(@obj)
13+
copy.should == @obj
14+
end
15+
end
16+
17+
ruby_version_is "2.5" do
18+
it "returns self" do
19+
copy = @obj.public_send(@method)
20+
21+
copy.should equal(@obj)
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)