MrB
MrB

Reputation: 209

Ruby: How to include/install .bundle?

I'm new to Ruby. I have a .bundle file. I put it in the source folder and did

require('my.bundle')

But when I call the methods in the bundle, the definition is not found. Do I have to install them or include them in some other way to access them?

I am on Ruby version 1.8.7 (latest version on Mac).

Upvotes: 0

Views: 2407

Answers (1)

the Tin Man
the Tin Man

Reputation: 160549

I highly recommend using RVM to manage your Ruby installation, including your gems, so if you don't already have that, get it and follow the instructions for installing it. Make sure you do the part about modifying your bash startup script or you'll see weird behavior, like the wrong Ruby being called. Also, use the steps in "RVM and RubyGems" to install your gems or you can run into weird behavior with gems being installed under the wrong or an unexpected Ruby.

Second, use the gem command to install gems:

gem install gem_to_install

replacing "gem_to_install" with the name of the gem you want, and it will be installed into the appropriate gem folder for your Ruby.

If you are on Ruby 1.92, and trying to require a gem to use as a module in your code, use:

require 'gemname'

if it is installed via the gem command. And, if it is a module you wrote or have in your program's directory or below it, use:

require_relative 'path/to/gem/gemname'

If you are on a Ruby < 1.9 you'll also need to add require 'rubygems' above your other require lines, then use require './path/to/gem/gemname'.


Thanks, but my .bundle is not in gems. How do I install/require a .bundle file I already have?

If you wrote it look into rubygems/gemcutter or bundler for info on bundling and managing gems.

You can install a gem without using the app by going into the directory containing the gem and running setup.rb. See http://i.loveruby.net/en/projects/setup/doc/usage.html for a decent writeup or the official docs at: http://docs.rubygems.org/read/chapter/3

Upvotes: 1

Related Questions