15

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.

Craig Williams
  • 418
  • 4
  • 13

5 Answers5

12

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
  • 418
  • 4
  • 13
5

Yehuda Katz gem bundler is a very good option IMHO:

http://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:

http://github.com/rubiojr/canasto

erik
  • 6,406
  • 3
  • 36
  • 36
rubiojr
  • 716
  • 5
  • 3
4

If you're packaging a MacRuby application you can also add the --gem flag with macruby_deploy under the "Info" tab for your Deployment target.

This puts the specified gem in the site_ruby folder deep within your package.

The arguments I'm passing macruby_deploy for my app are:

--compile --embed --gem sequel --gem sqlite3
user229044
  • 232,980
  • 40
  • 330
  • 338
jpoz
  • 2,257
  • 1
  • 23
  • 29
2

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
  • 1,216
  • 11
  • 23
-5

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
  • 173
  • 3
  • 9
  • 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 Oct 18 '09 at 00:31