Does :sym.eql?("sym") misbehave in IronRuby? - ruby

I just installed Mono 2.10 on my Mac and proceeded to run my Ruby Koans which I had previously finished to see if IronRuby got the same results as Mac's native Ruby 1.8.7. One of the tests midway through failed, and the issue seems to be this:
In Ruby 1.8.7, the following expression is false:
:sym.eql?("sym")
=> false
However, in IronRuby, it is true. The version of IronRuby I'm running is 1.1.2.0, which apparently is comparable to Ruby 1.9.2, so I downloaded that to check - it gets the same behaviour as Ruby 1.8.7. Is this an issue with IronRuby's implementation?

This is a bug according to the Ruby Spec. The semantics of #eql? are that it is true if == is true and if the objects are of the same class.

Related

Syntax Error in Ruby Gem term-ansicolor

I have been following "How-to: Use Cucumber with .NET and C# under IronRuby" to set up Cucumber for .net on Windows. I had no problem installing Ruby, IronRuby and installing Cucumber, but when I came to this step, my troubles started:
Check to see if Cucumber under IronRuby works: icucumber –help
Here icucumber.bat is a file we write to tell IronRuby where to find gems. I just copied the script from the link above and changed the directories to match my installation directories.
I first got a bunch of require errors, which I fixed by installing Cucumber (0.6.4) according to "IRONRUBY: 0 TO CUCUMBER IN 15 MINUTES":
IronRuby isn’t quite ready for the latest version of Cucumber.
I also installed term-ansicolor by doing gem install term-ansicolor. At this point, although I got rid of the require errors, I got a new one:
c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/term-ansicolor-1.6.0/lib/term/ansicolor/rgb_triple.rb:8: syntax error, unexpected label
def self.convert_value(color, max: 255)
^
The file is pointing to rgb_triple.rb, which came with the term-ansicolor gem. So I do not understand what could have caused this error.
It seems that IronRuby isn't ready for the last version of term-ansicolor either. Around Ruby 2.0 it became possible to use keyword parameters (the max: 255 part in your error message) but since version 1.9 this can be simulated using hashes.
The last release of IronRuby I can find is 1.1.3 and it claims to be working towards compatibility with Ruby 1.9 but it seems kind of abandoned. So you can downgrade your gems even further or change your Ruby implementation to MRI or JRuby.

How to control which version of Ruby gets used when running bundle

In ~/src/project/ containing all the files, I'm attempting to run bundle and bundle install, but it tells me I need a gem called "buff-extensions" and that gem installer requires Ruby version >= 2.2.0 to work properly.
When I ran ruby --version, it said Ruby 2.2.4p230 is being used when run from that directory.
I know there are several versions of Ruby on the machine in several places, and I'm struggling to follow the paths and figure out which technology is using which piece.
The Bundler docs spell this out:
You can specify the required version of Ruby in the Gemfile with ruby. If the Gemfile is loaded on a different Ruby version, Bundler will raise an exception with an explanation.
ruby '1.9.3'
What this means is that this app has a dependency to a Ruby VM that is ABI compatible with 1.9.3. If the version check does not match, Bundler will raise an exception. This will ensure the running code matches. You can be more specific with the :engine and :engine_version options.
ruby '1.9.3', :engine => 'jruby', :engine_version => '1.6.7'
I finally figured out the exact incantation in order to get the intended result, and I now realize the situation is unreasonable to expect any stranger to attempt to answer.
It involved chef, and I was supposed to run chef exec bundle.

Ruby - syntax error, unexpected tLABEL

I am getting syntax error, unexpected tLABEL in below Ruby code. The error description is pointing to ':' after 'timeout'.
def self.run(*args, timeout: nil, environment: {})
# ...
end
I have no knowledge of Ruby. I have tried few things like replacing ':' with '=' or putting nil in {} but nothing seems to work.
My ruby version is 2.1.5.
IUQ-mini:~ IUQ$ rbenv versions
system
* 2.1.5 (set by /Users/IUQ/.ruby-version)
2.1.7
2.2.3
The particular code can be found here at line #38.
Few questions over SO points that this could happen due to misplaced braces but I did not see error - again my lack of Ruby knowledge!
Please help me to understand cause of this error and How can I resolve this?
Thanks
That won't work in ruby 1.9 (if in fact JRuby is limiting you to 1.9) as-is since the splat is expected to have a hash immediately following it if it's the first argument.
You can do something like this:
def self.run (environment = {}, timeout = nil, *args)
end
The only rub is you'll have to explicitly pass something (even nil) for timeout if you want to pass stuff in to be args[].
Calabash iOS and Android require ruby >= 2.0.
The latest released version of ruby is recommended.
JRuby of any version is not supported at this time.
Travis build
If you look at the info for that build, you'll see it failed because it was running on ruby 1.9.3.
I believe that you have ruby 2.0 installed. I don't think you are using it.
$ rbenv versions
system
1.8.7-p375
1.9.3-p484
2.0.0-p481
2.1.5
2.2.2
2.2.3
* 2.3.0 (set by /Users/moody/.rbenv/version) <== Active ruby in this dir
jruby-1.7.18
$ rbenv version # Active ruby in this directory
2.3.0
You never mentioned what version of run_loop you are using. You should update to the most recent stable release.
https://github.com/calabash/calabash-ios/wiki/Updating-your-run-loop-version

Ruby - Invalid Regex

Ruby 1.8.7 says:
/Users/user/.thor/916bf40c98406efffe9700e1ef02da24:194: undefined (?...) sequence: /(?<text>Version:)\s*(?<version>[\d\.]+)/
Ruby 1.9.3-p374 says something similar, but Ruby 1.9.3-p0 works just fine with it.
The actual code that's broken:
pattern = /(?<text>Version:)\s*(?<version>[\d\.]+)/
What am I doing wrong ?
The (?<k>...) notation expresses named capture, which was introduced in Ruby 1.9, which uses Oniguruma regex engine. With Ruby 1.8, you need to either change the regex to not use it, or install Oniguruma or Onigmo (an improved version of Oniguruma introduced in Ruby 2.0).
Your code works fine for me in Ruby 1.9.3-p374. I suspect that what you are doing wrong is still running 1.8.7 when you think you're using 1.9.3-p374. As noted by #sawa, your regex is using a feature introduced in 1.9.

Ruby 1.9.2 is backward compatible with 1.8.7?

I'm using Ruby 1.9.2 (Yarv).
When I install gems I just use "gem install ".
How can I know which Ruby version they are written in: 1.8.7, 1.9.1 or 1.9.2?
If I'm using the latest version and I install a gem that is written in 1.8.7, then that gem doesn't work?
Eg. Yardstick gem seems to not work with 1.9.2 but perfectly with 1.8.7.
How do you check what version each gem is using?
Could someone enlighten this topic for me.
Unfortunatelly there is no definitive way to check that as there are so many versions and variants or Ruby interpreters (Ruby, JRuby, Iron Ruby) and system platforms. Also one gem which is pure Ruby may not work on all platforms with same interpereter verson, because some OS specific properties could be used.
So you must trust the autor or docs he/she provided. Another way to make sure that your platform is right for gem just run tests enclosed to gem - every well written gem should have such.
There is also small tip: if file contains
# -*- encoding: utf-8 -*-
then autor probably developed the gem with 1.9.x in mind.
There's a website for answering the question: "Is it Ruby 1.9?"
http://isitruby19.com/
It doesn't look like anyone has reported on Yardstick yet:
http://isitruby19.com/yardstick
You could be the first, and report that it's broken in 1.9.

Resources