<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=RubyCocoa</id>
	<title>RubyCocoa - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=RubyCocoa"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=RubyCocoa&amp;action=history"/>
	<updated>2026-06-24T16:50:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=RubyCocoa&amp;diff=545215&amp;oldid=prev</id>
		<title>imported&gt;Bender the Bot: /* External links */ HTTP to HTTPS for SourceForge</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=RubyCocoa&amp;diff=545215&amp;oldid=prev"/>
		<updated>2025-08-11T03:10:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;External links: &lt;/span&gt; HTTP to HTTPS for &lt;a href=&quot;/index.php/SourceForge&quot; title=&quot;SourceForge&quot;&gt;SourceForge&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|MacOS framework}}&lt;br /&gt;
{{Portal|Free and open-source software}}{{More sources|date=December 2024}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;RubyCocoa&amp;#039;&amp;#039;&amp;#039; is a [[macOS]] [[Software framework|framework]] that provides a bridge between the [[Ruby (programming language)|Ruby]] and the [[Objective-C]] programming languages, allowing the user to manipulate Objective-C [[object (computer science)|object]]s from Ruby, and vice versa. It makes it possible to write a [[Cocoa (API)|Cocoa]] application completely in Ruby as well as to write an application that mixes Ruby and Objective-C code.&amp;lt;ref name=&amp;quot;:0&amp;quot;&amp;gt;{{Cite web |title=File: RubyCocoa - A Ruby/Objective-C Bridge — RubyCocoa Documentation |url=https://rubycocoa.github.io/ |access-date=2024-12-18 |website=rubycocoa.github.io}}&amp;lt;/ref&amp;gt; An Apple project called [[MacRuby]] was under development to replace RubyCocoa in 2008.&amp;lt;ref&amp;gt;{{Cite web |date=2010-04-02 |title=Pragmatic Forums {{!}} Does MacRuby change the game? |url=http://forums.pragprog.com/forums/76/topics/687#posts-4160 |access-date=2024-12-18 |archive-url=https://web.archive.org/web/20100402104046/http://forums.pragprog.com/forums/76/topics/687#posts-4160 |archive-date=2 April 2010 }}&amp;lt;/ref&amp;gt; A proprietary spin-off called [[RubyMotion]] was subsequently released in 2012, available for iOS, macOS and Android.&amp;lt;ref&amp;gt;{{Cite web |title=About RubyMotion {{!}} RubyMotion |url=http://www.rubymotion.com/about/ |access-date=2024-12-18 |website=rubymotion.com}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RubyCocoa is used for exploration of a Cocoa object&amp;#039;s features with [[Interactive Ruby Shell|irb]] interactively, prototyping of a Cocoa application, writing a Cocoa application that combines the features of Ruby and Objective-C, and wrapping macOS&amp;#039; native [[GUI]] for a Ruby script.&amp;lt;ref&amp;gt;{{Cite web |title=Ruby and Python on OS X |url=https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/RubyPythonCocoa/Articles/RubyPythonMacOSX.html#//apple_ref/doc/uid/TP40005423-SW7 |access-date=2024-12-18 |website=developer.apple.com}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
RubyCocoa is [[free software]], released under both the [[Ruby License]] and the [[LGPL]].&amp;lt;ref name=&amp;quot;:0&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
RubyCocoa was started in 2001 by Hisakuni Fujimoto when he implemented a Ruby extension module to wrap NSObject and NSClassFromString function. Later it was integrated with Project Builder (which later became [[Xcode]]). In 2002 the project was registered on SourceForge and the development team began to grow.&lt;br /&gt;
&lt;br /&gt;
In 2006 the committers list was first joined by a developer from [[Apple Inc.|Apple]], Laurent Sansonetti, and then a RubyCocoa presentation was made during [[WWDC]]. Apple stated that RubyCocoa will be included and supported in [[Mac OS X v10.5]] “Leopard”.&lt;br /&gt;
&lt;br /&gt;
In August 2008, Sansonetti confirmed that [[MacRuby]] &amp;quot;is supposed to replace RubyCocoa.&amp;quot; in the future.&amp;lt;ref&amp;gt;{{Cite web |title=Pragmatic Bookshelf: By Developers, For Developers |url=https://pragprog.com |access-date=2024-12-18 |website=pragprog.com}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
RubyCocoa is sometimes interpreted as a set of bindings to the Cocoa frameworks, which is false. RubyCocoa is a real bridge between the Objective-C and Ruby programming languages.&lt;br /&gt;
&lt;br /&gt;
=== Lazy class import ===&lt;br /&gt;
RubyCocoa will import the Objective-C classes into the Ruby world on demand. For example, when you access &amp;lt;code&amp;gt;OSX::NSTableView&amp;lt;/code&amp;gt; for the very first time in your code, RubyCocoa will retrieve all the necessary information regarding this class from the Objective-C runtime and create a Ruby class of the same name that will act as a proxy. It will also import in the same way all the inherited classes.&lt;br /&gt;
&lt;br /&gt;
=== Forwarding messages ===&lt;br /&gt;
Every time the user sends a Ruby message to a proxy object, RubyCocoa will try to forward it to the embedded Objective-C instance, by translating the message name to an Objective-C selector and asking the Objective-C runtime to forward it.&lt;br /&gt;
&lt;br /&gt;
If an exception is raised from the Objective-C world, RubyCocoa will convert it to a Ruby exception and forward it to you.&lt;br /&gt;
&lt;br /&gt;
RubyCocoa uses the [[libffi]] library to call the Objective-C methods implementations.&lt;br /&gt;
&lt;br /&gt;
=== Automatic method overriding ===&lt;br /&gt;
RubyCocoa makes it easy to override an Objective-C method from Ruby, either in a subclass or directly to the class (as you would do in Objective-C using a category).&lt;br /&gt;
&lt;br /&gt;
Once your method is inserted, RubyCocoa will retrieve the signature of the existing Objective-C method and inject a new one to the Objective-C runtime, of the same signature, but which now points to your code.&lt;br /&gt;
&lt;br /&gt;
To accomplish this, RubyCocoa uses the [[libffi]] library to dynamically create a closure that will call the Ruby method, and just passes a pointer to that new closure to the Objective-C runtime.&lt;br /&gt;
&lt;br /&gt;
=== Accessing the C bits ===&lt;br /&gt;
Due to the nature of the Objective-C language, you can freely use [[C (programming language)|C]] from Objective-C code. In order to bridge the relevant C parts of an Objective-C framework, such as C structures, functions, enumerations, constants and more, RubyCocoa relies on the [[BridgeSupport]] project.&lt;br /&gt;
&lt;br /&gt;
RubyCocoa will interpret at runtime the BridgeSupport files (using the very fast [[libXML]]2&amp;#039;s xmlTextReader) and accordingly handle their content. It will for instance construct the Ruby proxy classes for the C structures and also create the functions.&lt;br /&gt;
&lt;br /&gt;
Note that the costly operations, such as localizing the symbols, are done on demand, and obviously only once.&lt;br /&gt;
&lt;br /&gt;
=== Format strings ===&lt;br /&gt;
RubyCocoa is able to detect APIs that use format strings, like NSLog or NSString.stringWithFormat, and appropriately convert the variable arguments to the types specified in the format string.&lt;br /&gt;
&lt;br /&gt;
=== Function pointers ===&lt;br /&gt;
RubyCocoa allows you to pass Ruby &amp;lt;code&amp;gt;Proc&amp;lt;/code&amp;gt; objects as function pointer arguments. It will then use the [[libffi]] library to dynamically create a closure and pass it to the underlying function/method.&lt;br /&gt;
&lt;br /&gt;
== Creation of Cocoa applications written in Ruby ==&lt;br /&gt;
&lt;br /&gt;
Installing RubyCocoa also automatically installs the corresponding [[Xcode]] templates. This allows developers to select &amp;quot;Cocoa-Ruby Application&amp;quot; as the Xcode project type and Xcode will generate all necessary files for them.&lt;br /&gt;
== How to call Objective-C methods from Ruby ==&lt;br /&gt;
To invoke an Objective-C method, you replace each colon in the method name except the last with an underscore. Thus, for example, the NSWindow instance method &amp;lt;code&amp;gt;initWithContentRect:styleMask:backing:defer:&amp;lt;/code&amp;gt; becomes &amp;lt;code&amp;gt;initWithContentRect_styleMask_backing_defer&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
All Cocoa classes and functions belong to &amp;lt;code&amp;gt;OSX&amp;lt;/code&amp;gt; module, so for example, the Objective-C code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
[[NSWindow alloc] initWithContentRect:frame&lt;br /&gt;
                            styleMask:NSTitledWindowMask&lt;br /&gt;
                              backing:NSBackingStoreBuffered&lt;br /&gt;
                                defer:NO]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will become:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
OSX::NSWindow.alloc.initWithContentRect_styleMask_backing_defer(frame,&lt;br /&gt;
  OSX::NSTitledWindowMask,&lt;br /&gt;
  OSX::NSBackingStoreBuffered,&lt;br /&gt;
  false)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, this decreases the code readability by rendering Objective-C parameter naming useless. So, there is another convenient way to write the method calls — the &amp;lt;code&amp;gt;objc_send&amp;lt;/code&amp;gt; method, which accepts Ruby symbols as parameter names. For example, the previous code can also be written as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
OSX::NSWindow.alloc.objc_send(:initWithContentRect, frame,&lt;br /&gt;
  :styleMask, OSX::NSTitledWindowMask,&lt;br /&gt;
  :backing, OSX::NSBackingStoreBuffered,&lt;br /&gt;
  :defer, false)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Advantages of RubyCocoa ==&lt;br /&gt;
* As Ruby is an interpreted language, there&amp;#039;s no need to recompile the application frequently during development.&lt;br /&gt;
* Some of Ruby&amp;#039;s rich features, like built-in [[regular expression]] support, make writing the code faster, and also make RubyCocoa an ideal tool for prototyping.&lt;br /&gt;
&lt;br /&gt;
== Disadvantages ==&lt;br /&gt;
* Ignoring the speed of the Ruby interpreter, RubyCocoa applications will always be slower than Objective-C/Cocoa applications due to the added overhead of object conversion.&lt;br /&gt;
* Because Ruby isn&amp;#039;t thread-safe, it isn&amp;#039;t possible to dispatch multiple native threads to execute RubyCocoa code. Ruby&amp;#039;s emulated threads, however, can be used.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://sourceforge.net/projects/rubycocoa/ RubyCocoa page on SourceForge]&lt;br /&gt;
&lt;br /&gt;
{{Ruby programming language}}&lt;br /&gt;
&lt;br /&gt;
[[Category:MacOS programming tools]]&lt;br /&gt;
[[Category:Ruby (programming language)]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Bender the Bot</name></author>
	</entry>
</feed>