How can I get the jruby version at runtime? - runtime

I need to get the jruby version for logging & debugging purposes.
I tried looking around JRuby.runtime for a version method, but I didn't find anything useful.
I also thought about using %x{jruby -v}. It works in most cases, except that there is always the possibility that more than one jruby version are installed, and I want to get the version of the currently running interpreter.
Did I miss something? Any suggestion?

You are looking for the global constant JRUBY_VERSION. This is a brother of VERSION, RUBY_ENGINE (not available under 1.8.x), RUBY_PLATFORM, etc.

Related

Do old gems always work on later versions of ruby?

I am using a quite recent version of ruby (2.5.1) but some old gems. I am having some issues. I was wondering, is it correct that some gems work only with certain versions of ruby?
If a gem worked with ruby 2.3.0, is it true that it will definitely work with 2.5.1 (i.e. because 2.5.1 > 2.3.0)? Or is that not always the case?
I guess what I'm asking is are newer ruby versions always backwards compatible with older gems?
If a gem worked with ruby 2.3.0, is it true that it will definitely
work with 2.5.1
This is not correct. Programming languages are evolving while growing. This means language maintainers are doing lots of improvements or refactorings that they are new features or removing old components from the language. When the language community announces for new features or removing old feature such as Fixnum in ruby, the developers should follow the instructions and refactor their codebase accordingly. In other words, developers should have a good test coverage to detect any fail and fix it instantly.
In your scenario, as well as I understand you do not have a test coverage. The only but the simple thing should do is just upgrade your gems' versions to latest.
Gem is simply a plug-in library written in Ruby.
Of course, Ruby is developing, new features are appearing, old ones are disappearing.
It's best practice to specify Ruby version in .gemspec file. For example, like this one.
But if not, then you have to manually check the performance. So you can read gem source code or try to use your gem and check it.
For automation, of course, it is best to use tests.
Starting at Ruby 2.1.0 the version policy has been that a change in the MINOR version may introduce API breaking changes.
Should any gem happen to use an API that changes, an incompatibility will arise.
The MINOR version number has changed twice between 2.3.* and 2.5.* so even if a gem happens to have been written in accordance with the documented API, there's no guarantee that it will continue to work unless the gem's maintainer takes the effort to test the gem (and upgrade it if necessary). Automated test suites help a lot.
A standard way to document version compatiblity that is actually tested against is by providing required_ruby_version in .gemspec files.
Interestingly, if a particular gem is really badly written, I imagine it might break even between compatible versions of Ruby. That's not something I've encountered in the Ruby ecosystem but I've made a similar mistake writing Java code (and Java is famous for its backward compatibility) where my own code accidentally used a class that wasn't part of the API. There are many gems. Who knows what's out there? :)

How do I determine my gem's required ruby version?

I am creating a gem and I have the suspicion that it may not work on certain Ruby versions. Is there a way to quickly check which Ruby versions it is compatible with? My current method is using RVM and switching to different Ruby versions to test, but that may be an inefficient way to do it. I was also wondering if I could narrow it down to a specific patch version.
#Matt Schuchard suggested the right way to do this (in the comment)
For example, you can check how to do this with GitHub Actions. You can test it not only for specific ruby version but also on different OSes
https://github.com/metanorma/metanorma/blob/master/.github/workflows/rake.yml

No autocompletion on required classes in Rubymine

I am requiring the date library and I would expect the methods from this library to appear in the code completion list (and hence get the documentation inline). However nothing appears. Why so?
What RubyMine and Ruby version are you using? Please try 4.5 Release Candidate, everything works fine for me in that version

problems with jruby version of ruby-debug

This problem no longer exists. ruby-debug works fine in jruby these days
Whenever I use 'n' to step over a line it steps into it instead. This happens to me on all the versions of jruby i've tried, the latest being 1.3.1
Does it work right for anyone? If so any idea how to fix it, because it's too painful when it steps into every function every time.
Also, I use it like this if it makes any difference.
require 'ruby-debug'; debugger
I've noticed this too. Have you tried using "step" instead, "step" seems to work for me.
currently doesn't work with 1.4.0 either, but ruby-debug does work with a trunk build of jruby

method redefined warning while running Merb 0.9.3

I get numerous "method redefined" warnings while running an application under Merb 0.9.3. Of course, I get this only when I run my script using the ruby -w option. Is there any way to get rid of the methods getting redefined (repeated loading of files) again and again?
Has this been resolved in Merb 1?
I don't know about your issue but Merb 1.0 works great for me. I also recommend using the latest version, there are a some bugs fixed even from 1.0.x.
Whether you get warnings may depend on which ruby version or warning level you use, as can be seen in this gist.
Or maybe they fixed stuff between 0.93 and 1.0 .

Resources