A fork of GNUstep's RIGS, updated for modern verions of macOS and Ruby.
- Ruby 2.7, 3.0, 3.1 or 3.2
- macOS 11, 12, or 13
You can run:
$ gem install obj_ruby
Or you can include in your Gemfile:
gem 'obj_ruby', '~> 0.1'
ObjRuby imports Objective-C classes dynamically at runtime. As an example, here is how you can import the NSDate
class into Ruby's namespace (for more examples, see this projects spec folder):
ObjRuby.import("NSDate")
date = ObjRuby::NSDate.dateWithTimeIntervalSince1970(42424242)
other_date = date.addTimeInterval(1000)
earlier_date = date.earlierDate(other_date)
Oftentimes you'll want to import all of a particular framework like Foundation or AppKit. ObjRuby provides convenience requires for each:
require "obj_ruby/foundation"
dict = ObjRuby::NSMutableDictionary.new
dict.setObject_forKey(ObjRuby::NSDate.new, "Hello!")
require "obj_ruby/app_kit"
app = ObjRuby::NSApplication.sharedApplication
app.setActivationPolicy ObjRuby::NSApplicationActivationPolicyRegular
app.activateIgnoringOtherApps(true)
alert = ObjRuby::NSAlert.new
alert.setMessageText("Hello world!")
alert.runModal
ObjRuby is a fork of GNUstep's RIGS, which according to it's author/maintainer Laurent Julliard:
was built in my spare time when my 3 children are in bed :-)
It's really a testimate to both Laurent and the Objective-C runtime in general that while much of the original code was written in 2001, an incredible amount of it runs unchanged over 20 years later on modern versions of macOS and Ruby.
This project is Copyright © 2023 Ryan Krug and thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.