This is a really basic ruby gems question. I’m familiar with writing simple ruby scripts like this:
#!/usr/bin/ruby
require 'time'
t = Time.at(123)
puts t
Now I’d like to use my own ruby gem in my script. In my rails project I can simply require 'my_gem'. However this doesn’t work in a stand-alone script. What’s the best/proper way to use my own gem in a stand-alone ruby script?
You should be able to simply require it directly in recent versions of Ruby.
If you are still on Ruby 1.8 (which does not require RubyGems by default), you will have to explicitly put this line above your attempt to load the gem:
Alternatively, you can invoke the Ruby interpreter with the flag
-rubygemswhich will have the same effect.See also: