Reputation: 1231
I have errors in my code which I believe are due to using an old Ruby version. For example, when I type rand(0.01..100.0)
in my IRB environment, I get this:
irb(main):001:0> rand(0.01..100.0) TypeError: can't convert Range into
Integer
from (irb):1:in `rand'
from (irb):1
from /usr/local/bin/irb:12:in `<main>'
I need to be using Ruby version 2.0.0. When I type in ruby -v
I get:
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
However, this is what I have done to try to install 2.0.0. Note that previously I have had RVM installed on my Macbook (now using rbenv) but I believe I have uninstalled RVM completely and do not have any trace of it in my system anymore.
I am using Homebrew:
$ brew update
Already up-to-date.
Installed Ruby using rbenv:
$ rbenv install 2.0.0-p481 rbenv:
/Users/GabbAHH//.rbenv/versions/2.0.0-p481 already exists continue
with installation? (y/N)
When I actually go into this folder in my local directory I confirm the 2.0.0 version and do not see any other versions.
I have also typed in rbenv global 2.0.0-p481
to my terminal with no issues or other return message seen.
However, below is my RubyGems Environment showing the older Ruby Version
$ gem env RubyGems Environment: - RUBYGEMS VERSION: 1.5.0 - RUBY VERSION: 1.9.2 (2010-12-25 patchlevel 136) [x86_64-darwin10.6.0] - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /usr/local/bin/ruby - EXECUTABLE DIRECTORY: /usr/local/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-10 - GEM PATHS: - /usr/local/lib/ruby/gems/1.9.1 - /Users/GabbAHH/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/
5) RBENV version
$ rbenv versions
system
* 2.0.0-p481 (set by /Users/GabbAHH//.rbenv/version)
6) echo $path returns a line break:
$ echo $path
$
7) which ruby
$ which ruby
/usr/local/bin/ruby
8)
$ $PATH
bash: /usr/local/bin:/usr/local/sbin:~/bin:/Users/GabbAHH//.rbenv/bin:/Users/GabbAHH//.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin: No such file or directory
So, despite all this, why am I still seemingly using Ruby 1.9.2? Let me know if there is other information I can display for you to help troubleshoot this.
Upvotes: 2
Views: 1367
Reputation: 1231
The section below (below the horizontal line) helped to resolve I believe the crux of the problem, but I still have some lingering issues. One of the symptoms is this when running rspec. It appears to have to do still with the rand method not functioning properly. I confirmed that it is likely an issue with my setup since I was able to test my same ruby code file with the same rspec file in another computer set up properly and the rspec passed all criteria. Whereas previously the rand method failed to be properly called in IRB as well, after the partial solution (below the horizontal line), it works properly in IRB.
1) valid_triangle? returns true for an equilateral triangle
Failure/Error: length = rand(0.01..100.0)
TypeError:
can't convert Range into Integer
# ./triangle_side_spec.rb:13:in `rand'
# ./triangle_side_spec.rb:13:in `block (2 levels) in <top (required)
The following entered in my .bash_profile did the trick. Don't really know exactly how that works though, I think pointing RBENV to the correct local directory? I think the solution was based from this link https://gist.github.com/MicahElliott/2407918
# Path for RBENV
test -d $HOME/.rbenv/ && PATH="$HOME/.rbenv/bin:$PATH"
# Rbenv autocomplete and shims
if hash rbenv 2> /dev/null; then
echo "Initializing rbenv"
eval "$(rbenv init -)";
else
echo "Can't find rbenv";
fi
Now I get a beautiful
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-darwin13.4.0]
:)
Upvotes: 1
Reputation: 1026
Did you run $ rbenv rehash
after installing the new Ruby version?
Installs shims for all Ruby executables known to rbenv (i.e., ~/.rbenv/versions//bin/). Run this command after you install a new version of Ruby, or install a gem that provides commands.
$ rbenv rehash
Upvotes: 0