O'Reilly logo

MacRuby: The Definitive Guide by Matt Aimonetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required