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.
To install a gem, use gem install [gem] . Browsing installed gems is done with gem list . For more information about the gem command, see below or head to RubyGems' docs.
By default, binaries installed by gem will be placed into: /usr/local/lib/ruby/gems/3.1. 0/bin You may want to add this to your PATH.
The interface for RubyGems is a command-line tool called gem which can install and manage libraries (the gems). RubyGems integrates with Ruby run-time loader to help find and load installed gems from standardized library folders.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With