Preface

MacRuby is Apple’s implementation of the Ruby programming language on top of the Objective-C technology stack. It allows developers to write native applications for the Cocoa environment using the popular Ruby syntax as well as the well-known and robust Objective-C and C libraries.

This book provides a guide to OS X development for MacRuby developers. Key concepts of MacRuby and Cocoa, as well the popular Cocoa APIs, are covered in this book. The book should help you leverage your existing programming knowledge to make you an efficient and productive MacRuby developer.

I became interested in MacRuby after many years working on/with/around Ruby web frameworks. I started using MacRuby after meeting Laurent Sansonetti (MacRuby lead developer at Apple). Laurent showed me that MacRuby had some interesting things to offer: a programming language that I liked as well as some great APIs and tools that allowed me to develop desktop applications easily and access some cool hardware resources.

This book was written using a version of MacRuby just prior 1.0. All the Xcode screenshots were created using Xcode 4.x. Most, if not all, of the content should be valid for MacRuby 1.x. and later versions.

The Purpose of This Book

The purpose of this book is to:

  • Teach MacRuby fundamentals.

  • Provide a guide to develop Cocoa applications using the MacRuby language.

  • Show concrete examples leveraging the Cocoa technology using MacRuby.

My personal goal is to provide you with a solid foundation, allowing you to understand how MacRuby is meant to be used and why things are designed the way they are. While this book is neither a Ruby book nor a Cocoa book, it should provide you with enough information to understand the MacRuby environment and create rich applications for the OS X platform.

Prerequisites

To get the most out of this book, you should have some programming experience and be familiar with the basics of object-oriented programming. I also assume some very basic knowledge of Ruby, because there are so many places to pick up that knowledge and the language is pretty simple. If you aren’t familiar with Ruby yet, go to the Ruby language website and read up. You’ll get more out of this book if you do that first. If you are already familiar with Ruby but would like to learn more, I recommend the excellent book, The Ruby Programming Language, by David Flanagan and Ruby’s creator, Yukihiro Matsumoto.

Also, even though we are going to cover some of the basics, understanding some fundamental Cocoa concepts will help. You can learn more about Cocoa as you go along, but should you find something confusing in this book, here are places to look for more information:

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Note

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “MacRuby: The Definitive Guide by Matt Aimonetti (O’Reilly). Copyright 2012 Matt Aimonetti, 978-1-449-38037-3.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://shop.oreilly.com/product/0636920000723.do

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

I would like to start out by thanking the two people without whom MacRuby would have never existed:

  • Yukihiro Matsumoto (Matz), for designing Ruby, such an elegant language.

  • Laurent Sansonetti, for writing the MacRuby implementation and leading the project.

I’m grateful to Apple for initiating and supporting the MacRuby project (with special thanks to Jordan Hubbard), and to Steve Jobs, who through his life proved that passionate people casting a vision of simplicity, efficiency, and interaction can design products that change the world. In addition, I’d like to thank my MacRuby teammates: Laurent Sansonetti, Vincent Isambart, Eloy Duran, Thibault Martin-Lagardette, Satoshi Nakagawa, Joshua Ballanco, Watson, Takao Kouji, Rich Kilmer, Patrick Thomson, and all the many contributors to the project over the years.

I would also like to thank J. Chris Anderson and Jan Lehnardt, who inspired me to release my work under the Creative Commons Attribution license, with a special “thank you” to Jan for introducing me to Mike Loukides. Speaking of Mike, I’d like to thank him and Andy Oram from O’Reilly for assisting and encouraging me as I wrote this book. Next, I’d like to thank the dozens of reviewers who gave me insightful comments and suggestions. You are too many to be listed, but know that I really appreciate you taking the time to help me make this book better.

Finally, I’d like to thank my friends and family for their continuous support and encouragement.

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.