rubyruby-2.4ruby-3

Can I use Ruby 2.4 code in Ruby 3 without getting any error?


I was wondering if I could use codes based on ruby 2.4 in ruby 3 (as in the programs, methodology, syntax and function names). I would like to slowly migrate to Ruby 3, but I would like to know if everything would be stable.

Do I need to download some package to make it stable? Is Ruby 3 backwards compatible (i heard they are not that much as they are fast innovator's, let's say compared to python which has backwards compatibility for all versions of 3.x but not that much of an innovator)?

Should I go through everything that I have written to make it compatible?

A bit of a tangent, but would it even be necessary for me to migrate to Ruby 3? I would presume that Ruby 2.4 already has enough features and updates for now for me to continue using it, and if I do not go up a version, I can always use Ruby 2.7.

Thanks!


Solution

  • The short answer is pretty No.

    You will have as many compatibility issues as many legacy code you have.

    Try to reach some resources like https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html

    But still, If you have well-written tests, they will fail, and deprecation warnings will occur. Those will be some kind of map for you(by fixing issues) to reach a new version.