I'm working with a Ruby 1.8 based gem that relies heavily on the pack method. Running the following on different Ruby versions, yields different results:
["0"].pack("B*")
In Ruby 1.8.7 I get "\000" as a result. In Ruby 2.2.0 I get "\x00". How would I go about getting the same results in 2.2 as in 1.8?
Related
In Rails 5.1.4 using Ruby 2.3.5, I get this behavior:
>> [].sum
#> nil
I'd like to upgrade to Ruby 2.4, where Enumerable#sum is implemented natively. Testing this in IRB using Ruby 2.4.2, I get this result:
>> [].sum
#> 0
That's OK, and I can handle the different result. But going back to the Rails console in Rails 5.1.4 using Ruby 2.4.2, I get this:
>> [].sum
#> NoMethodError: undefined method `each' for nil:NilClass
However, in a newly created Rails 5.1.4 project, I don't get this error. What's going on here?
Looking at the source for the Active Support enumerable extensions it definitely seems like something odd is going on because you shouldn't have been getting the behaviour you described for Rails 5.1.4 using Ruby 2.3.5 i.e. you should have been getting 0 not nil there too.
Active Support's Array#sum checks if Ruby's own sum can be used by checking first.is_a?(Numeric). This will be false for an empty array so the call to super will call Enumerable#sum and both implementations of that have a default of 0.
Try [].method(:sum).source_location in the Rails console of your existing project to see if Array#sum is being overridden somewhere.
if that returns the expected line from active_support/core_ext/enumerable.rb then the next step will be to check [].method(:sum).super_method.source_location and see if a customised Enumerable#sum is the culprit.
I think that your application have some overhidden on sum method. Look the example below with 2 new applications using the 2 different versions of ruby
/testapp# ruby --version
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
/testapp# rails --version
Rails 5.1.4
/testapp# rails c
irb(main):001:0> [].sum
=> 0
and the other version
/testapp# ruby --version
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
/testapp# rails --version
Rails 5.1.4
/testapp# rails c
irb(main):001:0> [].sum
=> 0
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.
Can Chef support newer versions of Ruby i.e. 2.0.0?
If not , is there a reason why?
In the documentation it specified up to 1.9.2
https://wiki.opscode.com/display/chef/System+Requirements+with+install (dead link)
Chef 11.6+ supports Ruby 2.0. Versions less than that will only work on Ruby 1.8 and 1.9.
Sources:
I work for Opscode
I use Chef on Ruby 2.0, 1.9, and 1.8
Documentation might need some updating. Chef supports ruby 2.0 according to this blogpost
http://www.opscode.com/blog/2013/09/03/chef-10-28-0-released/
Find the latest requirements at https://docs.chef.io/chef_system_requirements.html
Currently, Ruby 2.2.2 (or higher)
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 have ruby v 1.8 installed at C:\Ruby and its gems underneath.
I am planning to upgrade to v 1.9 , and it's installer try to default the app to c:\Ruby 1.9
How shall i proceed in order not to break my old gems .. including Rails , etc?
Thanks
Using the RubyInstaller, can I install Ruby 1.8 and 1.9 at the same time?
A: Yes. By using the RubyInstaller, Ruby 1.8 will be installed by default
to C:\Ruby, while 1.9 will be installed to C:\Ruby19. This is by design as
Ruby 1.8 and 1.9 offer a different API that may interfere with some RubyGems.
Source: http://wiki.github.com/oneclick/rubyinstaller/faq#dual_install
So go ahead and use the default of installing to C:\Ruby19.