1

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!

  • 1
    _"codes based on ruby 2.4"_ is very vague. Can you be more specific about the code you're trying to run? The easiest way to find out is to give it a try. You can use a Ruby version manager like rbenv, chruby or rvm to easily switch between different Ruby versions. – Stefan Oct 19 '21 at 08:36
  • As Stefan already wrote this depends on your application and how it was implemented. It is absolutely possible that even a complex old application still works on Ruby 3.0 but at the same time, it is possible a very simple application (for example a one-liner) will not work anymore. It really depends on what features of the ruby language were used. Only you can know or only you can test that out. – spickermann Oct 19 '21 at 13:57
  • @Stefan, by codes based on 2.4 I mean they were written on ruby 2.4, with all the functionality and syntax of then. I am wanting to migrate over into ruby 3 as it is newer. – Alireza Ghaffarian Oct 19 '21 at 19:26

1 Answers1

2

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.

dehelden
  • 39
  • 6
  • All that is said, based on assumption that you have a rails application. I'm not saying your application will not launch, but you will find different non-working stuff. – dehelden Oct 19 '21 at 02:22
  • 2
    That page is about compatibility between Rails and Ruby, not different Ruby versions. (and the OP didn't even mention Rails) – Stefan Oct 19 '21 at 08:39
  • The only option you have though is to check release notes of ruby versions and try to make an assumption, where your code would be affected. The best option as I See for you is to search for "deprecated" word in ruby releases. For example here is a 2.7.x release. Try to find some stuff here: https://rubyreferences.github.io/rubychanges/2.7.html – dehelden Oct 20 '21 at 14:11