views:

59

answers:

1

I am trying to play with redis on my Ubuntu machine and my little script doesn't work. I have installed redis gem and tried this little script (I know its pretty small)

require 'redis'
redis = Redis.new

I get this error :

./redis.rb:4: uninitialized constant Redis (NameError)
from redis.rb:2:in `require'
from redis.rb:2

when I comment the line 2, I dont get any problem. How come the class Redis is not recognized?

+2  A: 

Rename your file to something other than "redis.rb" (try test.rb), and make sure you require rubygems.

require "rubygems"
require "redis"

redis = Redis.new
Carl
just one last question : why redis.rb causes a conflict?
fenec
I believe it's because when you typed "require 'redis'" ruby actually tried loading your file you created called 'redis.rb'. It didn't look for the gem named 'redis', because it found a file called 'redis' in the script's directory. That's my best guess as to why.
Carl