I know it's possible to get the Ruby version (e.g. "1.9.3") via the RUBY_VERSION constant. However, I want to know how to go about determining the exact version (e.g.: "1.9.3-p0"). The reason is that there is a bug that was not fixed in earlier versions of Ruby 1.9.3 that is working in later versions, and I want some code in a gem I'm working on to account for this.
There is a RUBY_PATCHLEVEL constant as well. So you can get your version string as
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
At least in the newest Ruby (2.3.0), there is also a RUBY_DESCRIPTION constant:
RUBY_DESCRIPTION
# => "ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]"
Related
I have been trying to learn more about the rubygems system in ruby. One curious constant I have encountered is GEM_DEP_FILES. The ruby-doc.org page for Module: Gem has nothing to say about this value other than its name. Here is what I get in irb:
irb(main):002:0> Gem::GEM_DEP_FILES
=> ["gem.deps.rb", "Gemfile", "Isolate"]
Now "Gemfile" is the dependency mechanism we all know and love. I think; At least it is the same name.
My question is what about the others?
A wild guess is that "gem.deps.rb" is some old, obsolete predecessor to "Gemfile"? Maybe?
I have no clue at all about the entry called "Isolate".
I have looked with no success. Can anyone shed any light about these obscure entries?
In case it matters:
20 mysh>ruby --version
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
21 mysh>gem --version
2.5.2
http://ruby-doc.org/stdlib-2.3.3/libdoc/rubygems/rdoc/Gem.html
I am working to add a utility command to my mysh program that will display pertinent gem related info, so any info, advice, or guidance would be most welcome.
What's the naming syntax for different versions of ruby and which should I gravitate towards for running scripts? i.e., using rbenv I can install the following versions of Ruby 1.9.3:
1.9.3-dev
1.9.3-p0
1.9.3-p125
1.9.3-p194
1.9.3-p286
1.9.3-p327
1.9.3-p362
1.9.3-p374
1.9.3-p385
1.9.3-p392
1.9.3-p429
1.9.3-preview1
1.9.3-rc1
So we have several different types:
dev
p#
preview#
rc#
I believe I can assume that p# is for build fixes to the spec, preview# is a preview of the version spec and a precursor to rc#, the release candidate of the spec. So, this leaves dev. Is the dev tagged build what I should use for scripting or is it the development branch? And should I try to keep the latest p# installed? What's the best practice here?
Ruby uses semver for naming versions.
Best practice is keep your ruby as up-to-date as possible using the latest p# build.
Current version is Ruby 2.0.0-p195
If you're stuck in 1.9.3 for compatibility reasons, the latest patch is 1.9.3-p459.
You can see these versions on the Ruby homepage
I am getting an error when i am running any sort of rake command , it is showing me
rake aborted!
no such file to load -- config/environment
I am trying to upgrade the ruby version from ruby 1.8.7 to ruby 1.9.2 and rails 2.3.11 to rails 3.0.9 and when i am trying to start the server it is showing me
Value assigned to config.time_zone not recognized.Run "rake -D time" for a list of tasks for finding appropriate time zone names. (RuntimeError)
I am using RVM for this upgrade
ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
rails -v
Rails 3.0.9
You can't just upgrade from Rails 2 to 3 without some rather extensive preparation. All hell will break loose. Check out these Railscasts for starters:
http://railscasts.com/episodes/225-upgrading-to-rails-3-part-1
http://railscasts.com/episodes/226-upgrading-to-rails-3-part-2
http://railscasts.com/episodes/227-upgrading-to-rails-3-part-3
There might be newer resources out there. I'd also suggest to upgrade first ruby and then Rails, or vice versa, not both at the same time. Divide and conquer.
Peepcode Rails 3 Upgrade Handbook PDF
Rails Core suggestions: Plugin to run checks on your Rails 2.x/3.x to check for obvious upgrade points on the path to 3.0.
I had a exception when I switch to Ruby 1.8.7 on Snow Leopard
ArgumentError: wrong number of arguments (1 for 0)
/Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/quoting.rb:27:in 'to_s'
/Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/quoting.rb:27:in 'quote'
/Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/mysql_adapter.rb:190:in 'quote'
/Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:2042:in 'quote_value'
/Library/Ruby/Gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:2034:in 'attributes_with_quotes'
Application uses Rails 1.2.5: there is no chance to update rails in this app. Somebody have solution?
There will be a lot of compatibility issues with such an old version of rails and ruby 1.8.7. I would suggest using rvm to install multiple ruby versions / rails versions to test your app. I would also look into security patches as I am not sure if they are being backported to the 1.2.x branches.
I put this in a file inside config/initializers
class ::DateTime
alias_method :to_s, :to_formatted_s
end
The following code snippet works fine in 1.8.7 on Mac OS X, but not in 1.8.6 on Ubuntu. Why? Is there a workaround?
Works in 1.8.7:
$ ruby --version
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
ltredgate15:eegl leem$ irb
>> 6.times.map {'foo'}
=> ["foo", "foo", "foo", "foo", "foo", "foo"]
>>
But not in 1.8.6:
# ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]
Ruby Enterprise Edition 20090610
# irb
irb(main):001:0> 6.times.map {'foo'}
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1
irb(main):002:0>
Why is there a difference? What's the workaround for 1.8.6?
In 1.8.7+ iterator methods like times return an enumerator if they are called without a block. In 1.8.6 you have to do
require 'enumerator'
6.enum_for(:times).map {...}
Or for this specific use case you could simply do (0...6).map {...}
In Ruby 1.9, the library was changed so functions that did iteration would return an Enumerator object if they were called without a block. A whole host of other language features were also changed, and it was widely known that compatibility would be broken between Ruby 1.8.x and Ruby 1.9 in the interests of improving the language as a whole. Most people didn't find this too distressing.
The Ruby development team decided that Ruby 1.8.7 should be a transition release adding some of the library features that Ruby 1.9 introduced. They took a lot of criticism for the decision, and many enterprise Ruby users remained (and many still remain) running Rails on Ruby 1.8.6, because they feel the changes introduced 1.8.7 are just too large, and too risky. But nevertheless, 1.8.7 remains, and having iteration functions return Enumerators is one of the features that was incorporated.
It is this migration feature that you're seeing in 1.8.7, which is not present in 1.8.6.
sepp2k's answer gives a good workaround. There's not much for me to add on that count.
Because 1.8.6 #times yields on the given block, while 1.8.7 returns an Enumerator object you can keep around and implements Enumerable.
Ruby 1.8.7 introduces many changes. If you want to use them in Ruby 1.8.6, simply
require 'backports'
That's it. This gives you many methods of 1.9.1 and the upcoming 1.9.2 as well, although it's possible to require 'backports/1.8.7' for just the changes of 1.8.7, or even just the backports you need, e.g. require 'backports/1.8.7/integer/times'