Skip to content

Commit 07e8e7b

Browse files
committed
Implement String#to_d when 'bigdecimal/util' is required.
1 parent 9fea753 commit 07e8e7b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/mri/bigdecimal/util.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ class String
6666
#
6767
# See also BigDecimal::new.
6868
#
69+
# TruffleRuby: MRI defines this method in C. We define it in Ruby for simplicity & clarity.
70+
def to_d
71+
begin
72+
BigDecimal(self)
73+
rescue ArgumentError
74+
BigDecimal(0)
75+
end
76+
end
6977
end
7078

7179

0 commit comments

Comments
 (0)