<s>
RubyCocoa	B-Operating_System
is	O
a	O
macOS	B-Application
framework	B-Architecture
that	O
provides	O
a	O
bridge	O
between	O
the	O
Ruby	B-Language
and	O
the	O
Objective-C	B-Language
programming	I-Language
languages	I-Language
,	O
allowing	O
the	O
user	O
to	O
manipulate	O
Objective-C	B-Language
objects	O
from	O
Ruby	B-Language
,	O
and	O
vice	O
versa	O
.	O
</s>
<s>
It	O
makes	O
it	O
possible	O
to	O
write	O
a	O
Cocoa	B-Operating_System
application	O
completely	O
in	O
Ruby	B-Language
as	O
well	O
as	O
to	O
write	O
an	O
application	O
that	O
mixes	O
Ruby	B-Language
and	O
Objective-C	B-Language
code	O
.	O
</s>
<s>
An	O
Apple	O
project	O
called	O
MacRuby	B-Operating_System
was	O
under	O
development	O
to	O
replace	O
RubyCocoa	B-Operating_System
in	O
2008	O
.	O
</s>
<s>
A	O
proprietary	O
spin-off	O
called	O
RubyMotion	B-Application
was	O
subsequently	O
released	O
in	O
2012	O
,	O
available	O
for	O
iOS	O
,	O
macOS	B-Application
and	O
Android	O
.	O
</s>
<s>
Some	O
useful	O
applications	O
of	O
RubyCocoa	B-Operating_System
are	O
exploration	O
of	O
a	O
Cocoa	B-Operating_System
object	O
's	O
features	O
with	O
irb	O
interactively	O
,	O
prototyping	O
of	O
a	O
Cocoa	B-Operating_System
application	O
,	O
writing	O
a	O
Cocoa	B-Operating_System
application	O
that	O
combines	O
the	O
features	O
of	O
Ruby	B-Language
and	O
Objective-C	B-Language
and	O
wrapping	O
macOS	B-Application
 '	O
native	O
GUI	B-Application
for	O
a	O
Ruby	B-Language
script	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
is	O
free	B-Application
software	I-Application
,	O
released	O
under	O
both	O
the	O
Ruby	B-License
License	I-License
and	O
the	O
LGPL	B-Application
.	O
</s>
<s>
RubyCocoa	B-Operating_System
was	O
started	O
in	O
2001	O
by	O
Hisakuni	O
Fujimoto	O
when	O
he	O
implemented	O
a	O
Ruby	B-Language
extension	O
module	O
to	O
wrap	O
NSObject	O
and	O
NSClassFromString	O
function	O
.	O
</s>
<s>
Later	O
it	O
was	O
integrated	O
with	O
Project	O
Builder	O
(	O
which	O
later	O
became	O
Xcode	B-Operating_System
)	O
.	O
</s>
<s>
In	O
2006	O
the	O
committers	O
list	O
was	O
first	O
joined	O
by	O
a	O
developer	O
from	O
Apple	O
,	O
Laurent	O
Sansonetti	O
,	O
and	O
then	O
a	O
RubyCocoa	B-Operating_System
presentation	O
was	O
made	O
during	O
WWDC	O
.	O
</s>
<s>
Apple	O
stated	O
that	O
RubyCocoa	B-Operating_System
will	O
be	O
included	O
and	O
supported	O
in	O
Mac	B-Application
OS	I-Application
X	I-Application
v10.5	I-Application
“	O
Leopard	B-Application
”	O
.	O
</s>
<s>
In	O
August	O
2008	O
,	O
Sansonetti	O
confirmed	O
that	O
MacRuby	B-Operating_System
""	O
in	O
the	O
future	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
is	O
sometimes	O
interpreted	O
as	O
a	O
set	O
of	O
bindings	O
to	O
the	O
Cocoa	B-Operating_System
frameworks	O
,	O
which	O
is	O
false	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
is	O
a	O
real	O
bridge	O
between	O
the	O
Objective-C	B-Language
and	O
Ruby	B-Language
programming	I-Language
languages	I-Language
.	O
</s>
<s>
RubyCocoa	B-Operating_System
will	O
import	O
the	O
Objective-C	B-Language
classes	O
into	O
the	O
Ruby	B-Language
world	O
on	O
demand	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
you	O
access	O
OSX::NSTableView	O
for	O
the	O
very	O
first	O
time	O
in	O
your	O
code	O
,	O
RubyCocoa	B-Operating_System
will	O
retrieve	O
all	O
the	O
necessary	O
information	O
regarding	O
this	O
class	O
from	O
the	O
Objective-C	B-Language
runtime	O
and	O
create	O
a	O
Ruby	B-Language
class	O
of	O
the	O
same	O
name	O
that	O
will	O
act	O
as	O
a	O
proxy	O
.	O
</s>
<s>
As	O
stated	O
earlier	O
,	O
RubyCocoa	B-Operating_System
creates	O
special	O
proxy	O
objects	O
.	O
</s>
<s>
Every	O
time	O
you	O
send	O
a	O
Ruby	B-Language
message	O
to	O
a	O
proxy	O
object	O
,	O
RubyCocoa	B-Operating_System
will	O
try	O
to	O
forward	O
it	O
to	O
the	O
embedded	O
Objective-C	B-Language
instance	O
,	O
by	O
translating	O
the	O
message	O
name	O
to	O
an	O
Objective-C	B-Language
selector	O
and	O
asking	O
the	O
Objective-C	B-Language
runtime	O
to	O
forward	O
it	O
.	O
</s>
<s>
If	O
an	O
exception	O
is	O
raised	O
from	O
the	O
Objective-C	B-Language
world	O
,	O
RubyCocoa	B-Operating_System
will	O
convert	O
it	O
to	O
a	O
Ruby	B-Language
exception	O
and	O
forward	O
it	O
to	O
you	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
uses	O
the	O
libffi	B-Language
library	O
to	O
call	O
the	O
Objective-C	B-Language
methods	O
implementations	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
makes	O
it	O
easy	O
to	O
override	O
an	O
Objective-C	B-Language
method	O
from	O
Ruby	B-Language
,	O
either	O
in	O
a	O
subclass	O
or	O
directly	O
to	O
the	O
class	O
(	O
as	O
you	O
would	O
do	O
in	O
Objective-C	B-Language
using	O
a	O
category	O
)	O
.	O
</s>
<s>
Once	O
your	O
method	O
is	O
inserted	O
,	O
RubyCocoa	B-Operating_System
will	O
retrieve	O
the	O
signature	O
of	O
the	O
existing	O
Objective-C	B-Language
method	O
and	O
inject	O
a	O
new	O
one	O
to	O
the	O
Objective-C	B-Language
runtime	O
,	O
of	O
the	O
same	O
signature	O
,	O
but	O
which	O
now	O
points	O
to	O
your	O
code	O
.	O
</s>
<s>
To	O
accomplish	O
this	O
,	O
RubyCocoa	B-Operating_System
uses	O
the	O
libffi	B-Language
library	O
to	O
dynamically	O
create	O
a	O
closure	O
that	O
will	O
call	O
the	O
Ruby	B-Language
method	O
,	O
and	O
just	O
passes	O
a	O
pointer	O
to	O
that	O
new	O
closure	O
to	O
the	O
Objective-C	B-Language
runtime	O
.	O
</s>
<s>
Due	O
to	O
the	O
nature	O
of	O
the	O
Objective-C	B-Language
language	O
,	O
you	O
can	O
freely	O
use	O
C	B-Language
from	O
Objective-C	B-Language
code	O
.	O
</s>
<s>
In	O
order	O
to	O
bridge	O
the	O
relevant	O
C	B-Language
parts	O
of	O
an	O
Objective-C	B-Language
framework	B-Architecture
,	O
such	O
as	O
C	B-Language
structures	O
,	O
functions	O
,	O
enumerations	O
,	O
constants	O
and	O
more	O
,	O
RubyCocoa	B-Operating_System
relies	O
on	O
the	O
BridgeSupport	O
project	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
will	O
interpret	O
at	O
runtime	O
the	O
BridgeSupport	O
files	O
(	O
using	O
the	O
very	O
fast	O
libXML2	B-Application
's	O
xmlTextReader	O
)	O
and	O
accordingly	O
handle	O
their	O
content	O
.	O
</s>
<s>
It	O
will	O
for	O
instance	O
construct	O
the	O
Ruby	B-Language
proxy	O
classes	O
for	O
the	O
C	B-Language
structures	O
and	O
also	O
create	O
the	O
functions	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
is	O
able	O
to	O
detect	O
APIs	O
that	O
use	O
format	O
strings	O
,	O
like	O
NSLog	O
or	O
NSString.stringWithFormat	O
,	O
and	O
appropriately	O
convert	O
the	O
variable	O
arguments	O
to	O
the	O
types	O
specified	O
in	O
the	O
format	O
string	O
.	O
</s>
<s>
RubyCocoa	B-Operating_System
allows	O
you	O
to	O
pass	O
Ruby	B-Language
Proc	O
objects	O
as	O
function	O
pointer	O
arguments	O
.	O
</s>
<s>
It	O
will	O
then	O
use	O
the	O
libffi	B-Language
library	O
to	O
dynamically	O
create	O
a	O
closure	O
and	O
pass	O
it	O
to	O
the	O
underlying	O
function/method	O
.	O
</s>
<s>
Installing	O
RubyCocoa	B-Operating_System
also	O
automatically	O
installs	O
the	O
corresponding	O
Xcode	B-Operating_System
templates	O
.	O
</s>
<s>
This	O
allows	O
developers	O
to	O
select	O
"	O
Cocoa-Ruby	O
Application	O
"	O
as	O
the	O
Xcode	B-Operating_System
project	O
type	O
and	O
Xcode	B-Operating_System
will	O
generate	O
all	O
necessary	O
files	O
for	O
them	O
.	O
</s>
<s>
To	O
invoke	O
an	O
Objective-C	B-Language
method	O
,	O
you	O
replace	O
each	O
colon	O
in	O
the	O
method	O
name	O
except	O
the	O
last	O
with	O
an	O
underscore	O
.	O
</s>
<s>
All	O
Cocoa	B-Operating_System
classes	O
and	O
functions	O
belong	O
to	O
OSX	O
module	O
,	O
so	O
for	O
example	O
,	O
the	O
Objective-C	B-Language
code	O
:	O
</s>
<s>
As	O
you	O
can	O
see	O
,	O
this	O
decreases	O
the	O
code	O
readability	O
by	O
rendering	O
Objective-C	B-Language
parameter	O
naming	O
useless	O
.	O
</s>
<s>
So	O
,	O
there	O
is	O
another	O
convenient	O
way	O
to	O
write	O
the	O
method	O
calls	O
—	O
the	O
objc_send	O
method	O
,	O
which	O
accepts	O
Ruby	B-Language
symbols	O
as	O
parameter	O
names	O
.	O
</s>
<s>
As	O
Ruby	B-Language
is	O
an	O
interpreted	O
language	O
,	O
there	O
's	O
no	O
need	O
to	O
recompile	O
the	O
application	O
frequently	O
during	O
development	O
.	O
</s>
<s>
Some	O
of	O
Ruby	B-Language
's	O
rich	O
features	O
,	O
like	O
built-in	O
regular	B-Language
expression	I-Language
support	O
,	O
make	O
writing	O
the	O
code	O
faster	O
,	O
and	O
also	O
make	O
RubyCocoa	B-Operating_System
an	O
ideal	O
tool	O
for	O
prototyping	O
.	O
</s>
<s>
Ignoring	O
the	O
speed	O
of	O
the	O
Ruby	B-Language
interpreter	O
,	O
RubyCocoa	B-Operating_System
applications	O
will	O
always	O
be	O
slower	O
than	O
Objective-C/Cocoa	O
applications	O
due	O
to	O
the	O
added	O
overhead	O
of	O
object	O
conversion	O
.	O
</s>
<s>
Because	O
Ruby	B-Language
is	O
n't	O
thread-safe	O
,	O
it	O
is	O
n't	O
possible	O
to	O
dispatch	O
multiple	O
native	O
threads	O
to	O
execute	O
RubyCocoa	B-Operating_System
code	O
.	O
</s>
<s>
Ruby	B-Language
's	O
emulated	O
threads	O
,	O
however	O
,	O
can	O
be	O
used	O
.	O
</s>
