升级到 Ruby 2.7.6
在撰写本文时,Ruby v2.7.6
是 v3.0
之前的最新版本,如果应用程序使用依赖于 BigDecimal
的库,升级到 v2.7.6
可能会遇到重大问题。
The problem
NoMethodError:
undefined method `new' for BigDecimal:Class
The reason for the above error is since ruby v2.7
, the bigdecimal
gem is upgraded to v2.0
with a breaking change that drops BigDecimal.new
support.
The solution
- For app code, replace
BigDecimal.new
withBigDecimal()
- bd = BigDecimal.new(100)
+ bd = BigDecimal(100)
- For app using database gem such as
mysql2
with version older thanv0.5
, upgrade the gem tov5.0+
in Gemfile and runbundle update mysql2
- gem 'mysql2', '0.4.10'
+ gem 'mysql2', '0.5.4'
- (Not-recommended) Lock
bigdecimal
to an older version beforev2.0
if no other solutions work, for example
gem 'bigdecimal', '1.4.4'
参考资料