views:

1071

answers:

4

How do you use gems from a MacRuby .5 application on Snow Leopard? Do I need to specify the gem path? If so, how do I do this?

Best scenario is to package the gems inside the application so the user would not have to install them when the app is distributed.

+2  A: 

1st u will have to install the gem:

$ sudo gem install gem_name

then simply require it on your program, u will have to require the 'rubygems' also:

require 'rubygems'
require 'gem_name'
Raafat
Hi Raafat,Thanks for the reply. I have the gems installed and use them everyday in normal scripting. I am requiring rubygems and the gems after that. The error is a load error. These are working:require 'rubygems'require 'bacon'require 'net/http'require 'uri'This is not.require 'nokogiri'require 'appscript'
Craig Williams
+3  A: 

To use gems in a MacRuby project you need to use:

$ sudo macgem install gem_name

Not all gems are compatible with MacRuby, yet.

Craig Williams
+1  A: 

Gems that are written in C are not usable from MacRuby yet. So, no nokogiri for the time being.

To package the gems, the just released MacRuby 0.5 beta 2 includes the tool macrubyc, which packages the MacRuby framework inside your bundle. They also added support for doing this directly from Xcode in just one step.

Victor Jalencas
A: 

Yehuda Katz gem bundler is a very good option IMHO:

github.com/wycats/bundler

Anyway, there are many other options such as creating a vendor/ directory in your app bundle adding each vendor subdir to the ruby library search path in rb_main.rb:

$:.unshift File.join(File.dirname(FILE), 'vendor/rest-client/lib') $:.unshift File.join(File.dirname(FILE), 'vendor/crack/lib') require 'rest-client' require 'crack'

I'm using the latter approach here:

github.com/rubiojr/canasto

rubiojr