NameError: uninitialized constant

I recently opened up pry, ran this:

test =

but got this:

NameError: uninitialized constant TestGem

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.

require 'guess_incorrect_gem_name'
LoadError: cannot load such file -- guess_incorrect_gem_name

Eventually it seemed to be correct:

require 'guess_gem_name'
=> true

but this didn’t work:

test =
NameError: uninitialized constant GuessGameName

but by looking at the gem file name via:

ls ~/.rvm/gems/ruby-2.1.5/gems/gem_name/lib/gem_name/gemname.rb

I eventually used:

require "gem_name/gemname"

which worked. E.g.

test =
=> #<GemName:0x007fc8aae926c0>

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:

gem install gem_name
> # require with 
> require 'gem_name/gemname'
> # use with
> test =

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.


gem install daemons

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

require 'rubygems'        # if you use RubyGems
require 'daemons''myserver.rb')

3. and use it from the console like this:

$ ruby myserver_control.rb start
    (myserver.rb is now running in the background)
$ ruby myserver_control.rb restart
$ ruby myserver_control.rb stop


Cinch – super simple IRC bots

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

require ‘cinch’

bot = do
configure do |c|
c.server = “
c.channels = [“#cinch-bots”]

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


Just install using:

gem install cinch

Getting Started (in Markdown):

and the docs:

Other IRC Bot frameworks: