Irb Error: undefined method 'split' - ruby

I recently opened up irb, and now all of a sudden every time I run irb it gives me this error:
load error: /Users/addisonbean/.rvm/rubies/ruby-2.1.2/.irbrc
NoMethodError: undefined method `split' for nil:NilClass
/Users/addisonbean/.rvm/scripts/irbrc.rb:45:in `<top (required)>'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/.irbrc:11:in `<top (required)>'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/init.rb:236:in `load'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/init.rb:236:in `run_config'
/Users/addisonbean/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/init.rb:19:in `setup'
irb(main):001:0>
But as I've shown you it still gives me the prompt after all the errors
This is all the code inside of /Users/addisonbean/.rvm/rubies/ruby-2.1.2/.irbrc (the numbers are line numbers)
8 if ENV["rvm_path"].nil?
9 require File.join(ENV["HOME"], "irbrc")
10 else
11 require File.join(ENV["rvm_path"], "scripts", "irbrc")
12 end
And I have no ~/.irbrcw
I would love some help on this, thanks!

Looking at line 45 of rvm's scripts/irbrc.rb, we can find that split being called on path. It would seem that for some reason, your path is nil - probably because one of those rescue nil blocks is running.
I wouldn't advise hacking around the internals of rvm, but it looks like you can fake this by setting the environment variable $rvm_ruby_string, as irbrc.rb checks that before it tries to figure it out. Setting it to "2.1.2" should match what it calculates.

These steps solved my problem:
find the current ruby version
ruby -v
example:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
remove this version
rvm remove 2.1.2
install again
rvm install 2.1.2

Related

Ruby Error: undefined method `start_with?' Using Net::SSH.start

The ruby version I'm using is 1.8.6
I installed gem "net/ssh" using command "gem install net-ssh"
But on running the following script
require 'rubygems'
require 'net/ssh'
HOST = '10.102.5.100'
USER = 'user'
PASS = 'test'
Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
result = ssh.exec!('stat ssl')
puts result
end
Error:
/usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `load': undefined method `start_with?' for "*":String (NoMethodError)
from /usr/local/rubygems/lib/rubygems/custom_require.rb:36:in `partition'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `each'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `partition'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `load'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:81:in `foreach'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:81:in `load'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:63:in `for'
from /usr/local/rubygems/lib/rubygems/custom_require.rb:36:in `inject'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `each'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `inject'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `for'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh.rb:239:in `configuration_for'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh.rb:182:in `start'
from TestSSH.rb:9
Why do I get this error?
As the comments on your question point out, the problem arises because Ruby 1.8.6 doesn't have the String#start_with? method. The best solution would be to upgrade to a newer Ruby.
That said, according to the net-ssh README, versions prior to 2.5.1 support Ruby 1.8.x. A visual inspection of the file lib/net/ssh/config.rb as of net-ssh version 2.5.0 confirms that it doesn't use the start_with? method, so you might try that one. Be sure to read the changelog to make sure that the features you need are present in the version you use.

Install linalg for ruby in MAC OS failed

I follow the below guideline to install the linalg for Ruby env.
http://www.quora.com/Installation-Instructions/How-do-I-install-Ruby-linalg-library-on-Mac
It works, but when I try to require the lib in 'irb', it raise the error.
Environment: Ruby:2.0.0-p0 lapack:3.5.0 (I also tried 3.4.0)
I already spend on 3 hours but didn't figure out the problem.
Here's the error, when I try to require the lib in command line.
It seems somewhere use 18 as parameter which exceed the max value as -2..15.
2.0.0-p0 :002 > require 'linalg'
ArgumentError: arity out of range: 18 for -2..15
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/linalg.rb:7:in `<top (required)>'
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from (irb):2
from /Users/xxx/.rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in `<main>'
I did fork and fixed compile for ruby 2/2.1.
You can try this fork: https://github.com/parallel588/linalg

Ruby MongoClient: Initializing from irb succeeds, initializing from script fails

I'm trying to initialize a MongoClient from a script but I am failing.
What I simply do is:
require 'mongo'
include Mongo
client = MongoClient.new("localhost", 27017)
and it fails with the following error:
/var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/cursor.rb:43:in `initialize': undefined method `connection' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/db.rb:564:in `new'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/db.rb:564:in `command'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:591:in `block in check_is_master'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:590:in `check_is_master'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:474:in `connect'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:698:in `setup'
from /var/lib/gems/1.9.1/gems/mongo-1.9.1/lib/mongo/mongo_client.rb:155:in `initialize'
from ./test.rb:52:in `new'
from ./test.rb:52:in `<main>'
But, when I try the exact same thing from irb, it works.
Ruby version is:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
irb is:
/usr/bin/irb1.9.1 --version
irb 0.9.6(09/06/30)
I also tried requiring 'rubygems', but from what i know, Ruby 1.9 doesn't need it.
Am I forgetting something?
This issue was resolved by re-installing ruby. I never found out what the problem was and what was causing it.
Thanks for everyone's help.

Rbenv/Pow - Bundler::RubyVersionMismatch (Error starting application)

I am getting the following error each time i try run my app through pow
Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
I am just trying to link my project with pow and apparently i have a different version of ruby? i am using rbenv to manage my ruby versions. i have set rbenv to set 2.0.0-p0 locally, if i call ruby -v i get ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.4.0]
$rbenv versions
system
1.9.3-p327
* 2.0.0-p0 (set by /Users/fortknokx/Personal work/cave/.rbenv-version)
i tried to 'rbenv rehash' and refresh the '.ruby-version' nothing seems to convince pow that i am using ruby 2.0.0
The full stack on the error that i get from pow is as follows
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/definition.rb:361:in `validate_ruby!'
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
~/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
~/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'3.5/lib/bundler/definition.rb:361:in `validate_ruby!'
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
~/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
~/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
~/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
some how pow thinks i am on 1.9.3-p327?? any one had a simular issue. is it a ruby 2.0.0 thing or is it pow and rbenv having a boxing match?
There are some issues with using pow and rbenv as chronicled here: rbenv does not work well with pow
The problem seems to center on some PATH issues with the powconfig file, hence the reason pow is trying to use your default ruby install (assuming 1.9.x) vs. what you designated via rbenv. If you are using OSX mavericks, add the following to your ~/.powconfig file, restart pow once the change is made, and you should be good to go. (per the last suggestion):
export RBENV_ROOT=/usr/local/var/rbenv # Might not be necessary for pre-Mavericks OSX
eval $(rbenv init -)
export PATH=$(rbenv root)/shims:$(rbenv root)/bin:$PATH

Ruby version errors / crack/xml in irb

Because of a bug with Float#round in Ruby 1.8.6, I was forced to upgrade to 1.9.3 and boy was that awful. After install, irb didn't work, complaining of a lack of psych. So I tried to install the gem, but it was angry that libyaml didn't exist, so I installed that. Not sure why they weren't included if they were so important.
Now when I use require 'Location.rb' (after having to specify that I actually do want to look in the current folder... using $LOAD_PATH), I get this error:
LoadError: cannot load such file -- crack/xml
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/ap-0.1.1/lib/ap.rb:2:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/tyre77/Dropbox/Aurora/GMap.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
What does this mean? Also, when I execute ruby -v, it lists my version as 1.9.3p0 but this is dicking around in 1.9.1? All I want is my irb back and working!
It turned out that Ruby was looking for an XML parser called 'crack'. I don't know why it is referencing 2 versions of Ruby or why these dependencies aren't included in the Ruby build (since irb won't work without them) but to fix I installed the crack gem. sudo gem install crack
you can use
require_relative 'Location.rb'
or
require './Location.rb'

Resources