Using Gems with MacRuby Using Gems with MacRuby ruby ruby

Using Gems with MacRuby


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

$ sudo macgem install gem_name

Not all gems are compatible with MacRuby, yet.


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


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