Can't use `gem-install` command in pry - ruby

I tried to install a gem by using gem-install command in pry, but it failed.
% pry
pry(main) > gem-install pry-doc
NoMethodError: undefined method `split' for nil:NilClass
from /Users/ironsand/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pry-0.10.1/lib/pry/rubygem.rb:60:in `install'
I could install the gem by using gem command from bash.
Is there something I must configure to use gem-install command in pry?

I hadn't used PRY for a while.
Looking through the source code found the gem-install command code.
Look at your Gem.configuration['gem'] and you will find that it is nil.
It looks like this comes from your ~/.gemrc settings or default values.
In your ~/.gemrc file, if you place the line gem: ''
This solved the issue for me as it is no longer doing the split on nil, but on the assigned value for gem: key in the .gemrc file.

Related

Ruby require causing undefined local variable

I am a complete noob to Ruby. I wish to execute a file that I have taken from an Amazon AWS IoT page, but I have problems with the initial require as below.
I am using Ubuntu 18.04, I have installed ruby with sudo apt-get install ruby-full , and also sudo gem install mqtt . The file is called iot-connector.rb. I execute the file with ruby iot-connector.rb . It's obvious that it cannot find these require files, but how do I tell Ruby to find them. Thanks.
require ‘rubygems’
require ‘mqtt’
#more code....
The error I get :
Traceback (most recent call last):
iot-connector.rb:1:in `<main>': undefined local variable or method `‘rubygems’'
for main:Object (NameError)
You use wrong type of quotes, use regular ones instead of backquotes:
require 'rubygems'
require 'mqtt'
Backquotes are used to run shell commands, btw. it's quite strange you get ruby errors here, I'd expect sth like:
[29] pry(main)> `rubygems`
Errno::ENOENT: No such file or directory - rubygems

Ruby undefined local variable byebug

I'm executing the file app.rb in my rails project and trying to step through it using the byebug gem, but I get an error saying 'byebug' is an undefined local variable. I'm running the code using the command 'ruby app.rb'. Is there a different way to step through a ruby file when executing it this way via the command line?
$ bundle install
Fetching gem metadata from https://rubygems.org/.....
Resolving dependencies...
Using byebug 6.0.2
Installing pg 0.18.3
Using bundler 1.6.2
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ ruby app.rb
app.rb:17:in `block in <main>': undefined local variable or method `byebug' for main:Object (NameError)
from app.rb:15:in `glob'
from app.rb:15:in `<main>'
Looks like I just had to add require "byebug" at the top my app.rb file.
Another debugging option is the debugger gem:
require 'debugger'; debugger
https://github.com/cldwalker/debugger

Trying to use line comand in gem: gem install shopify_theme

I am new to ruby and am trying to use the line command:
gem install shopify_theme
However, I get an error
NameError: undefined local variable or method 'shopify_theme' for main:Object
from <rb>:2
from C:/Ruby21/bin/irb:11:in '<main>'
I assume this has something to do with my local files? I've used Dir.chdir to target my folder. Also, I have the gem file here as well.
ref: https://github.com/Shopify/shopify_theme
Thank you and any help is greatly appreciated!
You may be in the ruby console. Exit the ruby console and use cmd.exe!

Ruby Gems "NameError: undefined local variable or method 'update' for main:Object" on every command

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.

awesomeprint in irb unrecognized

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.

Resources