NameError: uninitialized constant

I recently opened up pry, ran this:

but got this:

Not greatly helpful.

It turned out that, despite adding it to my Gemfile and running

I still needed to require the file in pry.

However, the name of the file isn’t obvious if it’s not your own gem. E.g.

Eventually it seemed to be correct:

but this didn’t work:

but by looking at the gem file name via:

I eventually used:

which worked. E.g.

This all seems a lot of guess work.

What I’d like to see (and I’m sure there must be a way of doing this but Google’ing and searching StackOverflow has not turned anything up) is something like this:

Ruby LoadError

Ever get this message?

/Users/me/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- <some_gem_i_need> (LoadError)
from /Users/me/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
require’
from <your_script>.rb:1:in `<main>’

You and Ruby may have different ideas exactly where that gem was installed.

For example, you could have used sudo when installing a gem and installed it at a path that Ruby wasn’t expecting or can’t access. Try using plain old ‘gem install’

How to make a Ruby script into a daemon process

Use Daemons.

1.Install

gem install daemons

2. Then, say you have myserver.rb, create a control script, myserver_control.rb, like this:

3. and use it from the console like this:

http://daemons.rubyforge.org/

 

Cinch – super simple IRC bots

Here’s an example of a simple IRC bot using Cinch:

require ‘cinch’

bot = Cinch::Bot.new do
configure do |c|
c.server = “irc.freenode.org”
c.channels = [“#cinch-bots”]
end

on :message, “hello” do |m|
m.reply “Hello, #{m.user.nick}”
end
end

bot.start

Just install using:

gem install cinch

https://github.com/cinchrb/cinch#readme

Getting Started (in Markdown): https://github.com/cinchrb/cinch/blob/master/docs/getting_started.md

and the docs: http://rubydoc.info/gems/cinch/frames

Other IRC Bot frameworks: https://www.ruby-toolbox.com/categories/irc_bots