I'm trying to set up editing within irb using vim as described in this vimcast: http://vimcasts.org/episodes/running-vim-within-irb/
I did the gem install interactive_editor and it seemed to install the gem to /home/me/.gems/ruby/1.9.1/gem/interactive_editor, and I also edited my .irbrc file and added:
require 'rubygems'
require 'interactive_editor'
but when I try to run vi from irb I get this:
NameError: undefined local variable or method `vi’ for main:Object
from (irb):1
I am very new to Ruby/gems etc... I don't even know where to begin. Googling this error didn't really help, I only found a few people with the same issue and no answers.
I'm on Ubuntu 10.04, I have Ruby 1.9.1 installed... not sure about the versions for irb or rubygems.
Thanks a lot!
Here's the output from irb and ruby... something's obviously wrong.
aki#drom:~$ ruby -v
ruby 1.9.0 (2008-10-04 revision 19669) [i486-linux]
aki#drom:~$ irb -v
irb 0.9.5(05/04/13)
aki#drom:~$ irb
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'interactive_editor'
LoadError: no such file to load -- interactive_editor
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
I figured it out, my $GEM_HOME variable was not set properly. I had set it to
/home/me/.gems/ruby/1.9.1/gem/
instead of
/home/me/.gems/ruby/1.9.1/
This fixed it.
Thanks for your help!
Related
I'm attempting to set up a Watir environment. I had several issues actually installing the gems necessary, so I uninstalled and reinstalled Ruby 1.9.3 (I'm running Windows 7.) Now, I can't do any installs, updates, etc. from the ruby command line. Here is an example of some simple commands that should work but are not:
C:\Users\Matt Adams>irb
irb(main):001:0> gem -v
NameError: undefined local variable or method `v' for main:Object
from (irb):1
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):002:0> gem update
NameError: undefined local variable or method `update' for main:Object
from (irb):2
from C:/Ruby193/bin/irb:12:in `<main>'
I can start ruby irb, but that's it. Its almost as if none of the ruby commands were installed. Anyone have any suggestions? Note that I've already done a re-install.
IRB is there for you to try out Ruby commands or snippets and see immediate responses. If you want to install or update gems, I suggest you get off IRB first by running "quit" and follow whatever instructions you have on your hand.
I know the command for this is: require file name
but I guess this command is for ruby 1.9.4 and I am using ruby 2.0.0
the exact message is.
$require start.rb
LoadError: cannot load such file -- start.rb
from /home/aka/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/aka/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from (irb):2
from /home/aka/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'
Thanks in advance
Inside irb
>> require './start'
=> true
The file start.rb being in the same folder as you are, and the required file being in quotes, prefaced with the relative location ./ as shown.
This should work for you in Ruby from 1.8 on to 2.0 and beyond.
According to the docs, require will look for start.rb in the $LOAD_PATH since it does not resolve to an absolute path. In this case, the LoadError is telling you that start.rb is not in your $LOAD_PATH.
I am guessing that start.rb is in your current directory. You can use
>> require '/path/to/start.rb'
or
>> require './start.rb'
or
>> require './start'
This saves you some typing:
$ irb -r ./start.rb
If I require ap, irb returns true (I assume telling me that the awesomeprint gem has been successfully loaded). However if I issue the command ap f where f is a hash, I get:
NoMethodError: undefined method `ap' for main:Object
from (irb):5
from /usr/local/bin/irb:12:in `<main>'
Thoughts?
Here is my $LOAD_PATH:
"/usr/local/lib/ruby/gems/1.9.1/gems/multi_json-1.1.0/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/multi_xml-0.4.1/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/httparty-0.8.1/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/ap-0.1.1/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/psych-1.2.2/lib", "/usr/local/lib/ruby/gems/1.9.1/gems/crack-0.3.1/lib", "/usr/local/lib/ruby/site_ruby/1.9.1", "/usr/local/lib/ruby/site_ruby/1.9.1/x86_64-darwin11.3.0", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/vendor_ruby/1.9.1", "/usr/local/lib/ruby/vendor_ruby/1.9.1/x86_64-darwin11.3.0", "/usr/local/lib/ruby/vendor_ruby", "/usr/local/lib/ruby/1.9.1", "/usr/local/lib/ruby/1.9.1/x86_64-darwin11.3.0"
It seems ap is the 4th one.
The gem you want is called awesome_print, so sudo gem install awesome_print should fix it. May want to remove the other gem 'ap' which seems to be some http and xml related gem.
How do you install a library that is not a gem in Ruby?
I'm trying to use graphy.
In the example usage, it says to require 'graphy', but even when my ruby file is in the same directory as graphy.rb, I get the following error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- graphy.rb (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from foo.rb:1:in `<main>'
Tell ruby to look in the current dir using the -I flag:
ruby -I. my_script.rb
To see the ruby load path, add puts $: at the top of your script.
Everything works fine. I have pasted my IRB try below.
Yasky$ cd Projects/ruby/bruce-graphy-70f213b/lib/
lib Yasky$ irb
ruby-1.8.7-p352 :001 > require 'graphy'
=> true
ruby-1.8.7-p352 :002 > dg = Graphy::Digraph[1,2, 2,3, 2,4, 4,5, 6,4, 1,6]
=> Graphy::DirectedGraph[Graphy::Arc[2,3,nil], Graphy::Arc[1,6,nil], Graphy::Arc[2,4,nil], Graphy::Arc[4,5,nil], Graphy::Arc[1,2,nil], Graphy::Arc[6,4,nil]]
ruby-1.8.7-p352 :003 > exit
lib Yasky$
Explicitly specifying your current directory in your load path may do the trick.
EDIT: Oops, I was too late (:
In this particular case, the author is using Jeweler to manage his gemspec. I'm not that familiar with Jeweler, but AFAIR, you generate and install a Gem with rake install. You may need to generate a version number first with rake version:write MAJOR=0 MINOR=0 PATCH=1.
I am writing a script with Ruby/MongoDB that stores Tweets. After I gem-installed mongoid, this first-steps code throws an error:
require 'rubygems'
require 'mongo'
require 'mongoid'
Mongoid.database = Mongo::Connection.new('localhost').db('db')
# snippet from http://rujmah.posterous.com/using-mongoid-without-rails
NB. This is no Rails app, but a Terminal script.
The error I get is:
./mongoid.rb:10: uninitialized constant Mongoid (NameError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from mongoid.rb:3
It works in irb and I'm running ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0].
What am I doing wrong?
Edit August 2012
Somehow I got it to work. Alas, nearly a year on, I really can’t remember how. I will try to do better next time.
I hit the same issue while trying to get Bullet gem to work. The solution for me was to simply move gem 'mongoid', github: 'mongoid/mongoid' as the first line of the Gemfile. I find it really odd but that was how I got rid of that error.
I am using Ruby 2.1.0 and Rails 4.0.0