enh-ruby-mode and Ruby 3.1 syntax - ruby

From what I see, enh-ruby-mode doesn't seem to support the latest Ruby syntax updates of 3.1, "value omission in Hash literals" to be exact.
Is there a way to solve it?
If that's important, I'm using rbenv.
enh-ruby-program is "~/.rbenv/shims/ruby".
Ruby version is 3.1.2
ruby -c path/to/file outputs Syntax OK for the same file.
enh-ruby-mode plugin version is 20210120.201
As a workaround, I had to set enh-ruby-check-syntax for that 3.1 Ruby project.

Related

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?
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' ]

Ruby 2.4.1 Dir.children( dirname ) returns "undefined method `children' for Dir:Class"

I'm new to Ruby and trying to learn it. I'm using the latest Ruby version (2.4.1) and the interactive Ruby Shell.
I've come across the children method in the Dir class. I've tried the example from the documentation:
Dir.children("testdir") #=> ["config.h", "main.rb"]
but it doesn't seem to work, because I get the following message:
undefined method `children' for Dir:Class
What am I missing?
This seems to be some kind of documentation mess.
The Dir.children method was introduced with Feature #11302 into Ruby and was committed to trunk and eventually released with Ruby 2.5.0. However, it appears that the patch adding this method was not actually backported to Ruby 2.4 since dir.c of Ruby 2.4.1 doesn't mention the method. It's not immediately clear why the documentation for this method turned up at http://ruby-doc.org/
In any case, it appears you are yet out of luck with this method. You can however use the following equivalent code with your Ruby version:
Dir.entries('testdir') - [".", ".."]
It will return the exact same values as Dir.children('testdir') would in Ruby 2.5 and newer.

Warning parser/current is loading parser/ruby22

I'm newbie in Ruby, while excecuting a command I got this error.
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2-compliant syntax, but you are running 2.3.1.
My Ruby version is 2.3.1
My parser version is 2.4.0.0.
I don't know why parser is loading from ruby22 which is not even installed in my computer.
Any help would be appreciated.
In my case, I was running an old version of Rubocop (which relies on the parser gem). Removing/updating rubocop or whatever gem is using parser may fix your issue.

Ruby Squeel library deprecation of core extensions

I started maintaining a big app with tons of Squeel queries.
The latest Squeel version (>1.1) is deprecating code extensions:
DEPRECATION WARNING: Core extensions are deprecated and will be
removed in Squeel 2.0.
Is there an easy way to grep for the this deprecated symbol and hash core extensions?
I think you can use RuboCop to find the usage of deprecated methods.
Installed it with:
$ gem install rubocop
and then in your project root run
$ rubocop
EDIT:
You could actually use the idea from https://stackoverflow.com/a/5515144/1006863 to print a message every time a method is used.
Other option would be to redefine every method by add the deprecation or fork the project and add it yourself and then ask for a merge request. If it's denied you can keep using your version by specifying the repository in your Gemfile.

ruby-xslt, Centos and undefined symbol xsltLibxmlVersion

I have a rails application using the following environment:
CentOS release 5.7 (Final)
Rails 3.0.9
Rubygems 1.6.2
Ruby 1.9.2
Passenger
Apache2
The Development environment differs and is: Ubuntu 10.04, Ruby 1.8.7 which works like a charm. I can't change the production environment.
I use ruby-xslt, gem version 0.9.8, the problem is when I access the application I get an error:
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-xslt-0.9.8/lib/xml/xslt_lib.so: undefined symbol: xsltLibxmlVersion - /usr/local/lib/ruby/gems/1.9.1/gems/ruby-xslt-0.9.8/lib/xml/xslt_lib.so
The only solution I can find about this is:
http://amitsolanki.com/2010/04/undefined-symbol-xsltlibxmlversion-ruby-xslt-and-centos/
Which does not work for me.
I am stumped and would like to hear your opinions on what to do:
My ideas are as follows:
1) Don't use ruby-xslt - However this is the only ruby based xslt lib I could get to compile in development, which is why I used it. (but am open to suggestions).
2) Hack the ruby-xslt lib to remove the reference to the symbol, recompile and install. (tried but the error still appears so I may not be doing it right, I run "ruby setup.rb" for the gem again after the change but this is pure guesswork.)
3) Change the Ruby Environment to 1.8.7 as in development - don't think this will work as the problem is between the gem ruby-xslt and a linux library libxslt2.so and not the ruby env. (so actually not going to do this)
4) Add the symbol to the libxslt2.so lib, rebuild and install (but not worked with C language for 15 Years)
Any thoughts on this?
Regards
Paul
I solved this by using option number 1 and managed to get an older version of xslt-ruby installed (1.0.1), this involved installing a few libs as well.

Resources