Search code examples
rubyupgradebackwards-compatibility

Is ruby 2.7 and earlier code compatible with ruby 3.0.1?


I'm having difficulty deciding whether to build a new ruby gem in ruby 3.0.1 vs ruby 2.7. Is ruby code written in versions >=3.0.0 backwards compatible with versions >=2.5 or >=2.7? Can somebody working in ruby 2.7 consume a gem written in >=3.0.1, on the same note can someone working in >=3.0.1 consume a gem written in ruby 2.7? Are there any breaking changes in 3.0.1 that make it difficult to upgrade from 2.7?


Solution

  • Is ruby code written in versions >=3.0.0 backwards compatible with versions >=2.5 or >=2.7?

    No. For example:

    Other notable changes since 2.7. Keyword arguments are separated from other arguments. In principle, code that prints a warning on Ruby 2.7 won’t work.

    https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

    However, it is possible to write a library using the subset of Ruby that is compatible with 2.5 through 3.0. For example, PaperTrail aims to do this.

    # https://github.com/paper-trail-gem/paper_trail/blob/master/.github/workflows/test.yml#L66
    ruby: [ '2.5', '2.7', '3.0' ]