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 with BigDecimal()
- bd = BigDecimal.new(100)
+ bd = BigDecimal(100)
  • For app using database gem such as mysql2 with version older than v0.5, upgrade the gem to v5.0+ in Gemfile and run bundle update mysql2
- gem 'mysql2', '0.4.10'
+ gem 'mysql2', '0.5.4'
  • (Not-recommended) Lock bigdecimal to an older version before v2.0 if no other solutions work, for example
gem 'bigdecimal', '1.4.4'

参考文献

ruby