Chapter 13. Using Ruby Third-Party Libraries

In Chapter 12, you saw how to write or include Objective-C libraries in MacRuby apps using frameworks or dynamic libraries. This is very useful for existing Cocoa code or low-level Objective-C wrappers. However, the amount of free open source Ruby libraries is quite impressive. As a matter of fact, there are currently more published Ruby libraries than Perl libraries! This chapter explains how to access these Ruby resources.

RubyGems

Ruby libraries are usually packaged as gems, which are library packages used by the RubyGems standard library. A gem includes its own library files, defining a version number and dependencies on other libraries, if any. You can look for gems at the RubyGems site. In C Ruby, the default Ruby implementation, use the gem command-line tool to install gems on your system. In MacRuby, the gem command line is prefixed to avoid conflicting with the C Ruby command. Very much like irb is available as macirb, gem for MacRuby is available as macgem.

You can use the macgem command-line tool the same way you use gem. In this case, I am going to locally install the dispatch gem, a MacRuby-specific gem that adds an abstraction layer on top of the GCD API:

$ sudo macgem install dispatch

Notice that I’m installing the gem as a superuser (by prefixing the command with sudo), because the gems will be installed in the /Library/Frameworks/MacRuby.framework folder, which is owned by the root account.

While this is very useful, you can’t ...

Get MacRuby: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.