<rss version="2.0">
<channel>
<title>MacRuby Posts</title>
<link>http://macruby.org</link>
<description>News posts for the MacRuby project at Mac OS Forge.</description>
<language>en-us</language>
<lastBuildDate>2010-02-01T20:09:02-08:00</lastBuildDate>
<item>
<title>MacRuby 0.5</title>
<link>http://macruby.org/blog/2010/01/31/macruby05.html</link>
<description>&lt;p&gt;We are pleased to announce the final release of MacRuby 0.5. After months of hard work and two successful beta releases, we believe 0.5 is good enough to replace the previous stable release, 0.4.&lt;/p&gt;
&lt;p&gt;You can download it from &lt;a href=&quot;http://www.macruby.org/files/MacRuby%200.5.zip&quot;&gt;here&lt;/a&gt;. Please note that this package only runs on Snow Leopard and above. Users on Leopard can also use MacRuby by &lt;a href=&quot;/source.html&quot;&gt;building the sources&lt;/a&gt; from our repository.&lt;/p&gt;
&lt;p&gt;Remember that while MacRuby is progressing quickly, it is still not recommended for mainstream development yet. We believe that MacRuby is stable in a lot of areas but others are still a work in progress.&lt;/p&gt;
&lt;p&gt;As usual, please give it a try and be sure to &lt;a href=&quot;/contact-us.html&quot;&gt;report&lt;/a&gt; any problems you encounter to us.&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;re just getting started with MacRuby 0.5, make sure to check out our articles on the previous beta releases: &lt;a href=&quot;http://macruby.org/blog/2009/10/07/macruby05b1.html&quot;&gt;0.5 beta 1&lt;/a&gt; and &lt;a href=&quot;http://macruby.org/blog/2009/11/17/macruby05b2.html&quot;&gt;0.5 beta 2&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can read about all the changes since the last beta in this &lt;a href=&quot;http://lists.macosforge.org/pipermail/macruby-devel/2010-January/004064.html&quot;&gt;status report&lt;/a&gt; e-mail on the mailing-list, but here are the most visible changes:&lt;/p&gt;
&lt;h3&gt;HotCocoa Support&lt;/h3&gt;
&lt;p&gt;HotCocoa is a thin &amp;amp; idiomatic Ruby layer that sits above Cocoa and other frameworks, developed by Rich Kilmer. MacRuby 0.5 now supports HotCocoa.&lt;/p&gt;
&lt;p&gt;HotCocoa used to be developed inside the MacRuby project, but we decided that it would have a better life on &lt;a href=&quot;http://github.com&quot;&gt;GitHub&lt;/a&gt;, where it is far easier for developers to submit contributions. HotCocoa also has been transformed as a gem and is included in the 0.5 package installer. Be sure to require rubygems before using it.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
require 'rubygems'
require 'hotcocoa'
include HotCocoa
application do |app|
  win = window :size =&amp;gt; [100,50]
  b = button :title =&amp;gt; 'Hello'
  b.on_action { puts 'World!' }
  win &amp;lt;&amp;lt; b
end
&lt;/pre&gt;
&lt;p&gt;If you&amp;#8217;re interested in HotCocoa, make sure to &lt;a href=&quot;http://github.com/richkilmer/hotcocoa&quot;&gt;clone the project&lt;/a&gt; and start hacking!&lt;/p&gt;
&lt;h3&gt;More Elegant Ahead-of-Time Compilation&lt;/h3&gt;
&lt;p&gt;The macrubyc command-line tool has been improved to support the compilation of multiple Ruby source file into dynamic libraries. This is useful when you have several executables sharing the same Ruby code.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ cd /tmp
$ echo &quot;def hello(n); puts 'hello ' + n; end&quot; &amp;gt; t1.rb
$ echo &quot;def hello_world; hello 'world'; end&quot; &amp;gt; t2.rb
$ echo &quot;require 't1'; require 't2'; hello_world&quot; &amp;gt; test.rb
$ macrubyc t1.rb t2.rb -o code.dylib --dylib
$ file code.dylib 
code.dylib: Mach-O 64-bit dynamically linked shared library x86_64
$ macrubyc test.rb code.dylib -o test
$ rm t1.rb t2.rb test.rb 
$ ./test
hello world
&lt;/pre&gt;
&lt;p&gt;Also, macrubyc now comes with a man-page which provides more information on how to use it. Check it out!&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ man macrubyc
&lt;/pre&gt;
&lt;h3&gt;Grand Central Dispatch Support&lt;/h3&gt;
&lt;p&gt;In this release, we completed our GCD support. Every C API of Grand Central Dispatch is now available from MacRuby. We also completed documentation (as rdoc comments), covered everything with specs and we now intend to support this API in further releases.&lt;/p&gt;
&lt;p&gt;To get you started with GCD, we wrote a &lt;a href=&quot;/documentation/gcd.html&quot;&gt;separate tutorial&lt;/a&gt;. Check it out!&lt;/p&gt;
&lt;p&gt;We plan to provide higher-level, Ruby-centric API&amp;#8217;s for GCD in future releases.&lt;/p&gt;</description>
<pubDate>2010-01-31T15:33:21-08:00</pubDate>
<guid>http://macruby.org/blog/2010/01/31/macruby05.html</guid>
</item>
<item>
<title>MacRuby 0.5 beta 2</title>
<link>http://macruby.org/blog/2009/11/17/macruby05b2.html</link>
<description>&lt;p&gt;After a month of hard work we are pleased to offer the second beta of MacRuby 0.5. We are expecting one more beta before shipping the final 0.5.&lt;/p&gt;
&lt;p&gt;You can download it from &lt;a href=&quot;http://www.macruby.org/files/MacRuby%200.5%20beta%202.zip&quot;&gt;here&lt;/a&gt;. Please note that this package only runs on Snow Leopard and above. Users on Leopard can also use MacRuby by building the sources from our repository.&lt;/p&gt;
&lt;p&gt;Remember that this is a development version of MacRuby provided for testing and experimentation purposes only.  Even though many features are already quite stable at the time of this writing, some of them are still a work in progress.&lt;/p&gt;
&lt;p&gt;Please feel encouraged to give it a try and be sure to &lt;a href=&quot;http://www.macruby.org/contact-us.html&quot;&gt;report&lt;/a&gt; any problems you encounter to us. This will help us to ensure that the final release is of the highest  possible quality.&lt;/p&gt;
&lt;p&gt;You can read about all the changes since the first beta in this &lt;a href=&quot;http://lists.macosforge.org/pipermail/macruby-devel/2009-November/003286.html&quot;&gt;status report&lt;/a&gt; e-mail on the mailing-list, but here are the most visible changes:&lt;/p&gt;
&lt;h3&gt;Better Compatibility&lt;/h3&gt;
&lt;p&gt;We fixed many compatibility bugs, allowing MacRuby to run rdoc, ri, &lt;a href=&quot;http://rack.rubyforge.org/&quot;&gt;Rack&lt;/a&gt; and &lt;a href=&quot;http://www.sinatrarb.com/&quot;&gt;Sinatra&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;RI files are now generated as part of the project build and readable from the macri command-line tool.&lt;/p&gt;
&lt;p&gt;We are also able to run simple Rack and Sinatra web applications on MacRuby, using a simple GCD-based web-server that will be covered in an upcoming blog article.&lt;/p&gt;
&lt;p&gt;Additionally, MacRuby 0.5 beta 2 ships with experimental support for the BigDecimal, OpenSSL and JSON extensions.&lt;/p&gt;
&lt;h3&gt;Better Ahead-of-Time Compiler&lt;/h3&gt;
&lt;p&gt;Many compiler bugs have been fixed and the macrubyc utility is now able to generate fat binaries, via the &amp;#8212;arch argument.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ macrubyc hello.rb -o hello --arch i386 --arch x86_64
&lt;/pre&gt;
&lt;p&gt;Also, macrubyc will generate by default executables linking against MacRuby.framework dynamically, which greatly reduces the executable size. In order to build a full standalone executable, the &amp;#8212;static argument must be passed.&lt;/p&gt;
&lt;p&gt;A new utility, called macruby_deploy, is now available to help you deploy your MacRuby applications. It provides options to compile ahead-of-time your application&amp;#8217;s Ruby source code as well as relocating the MacRuby framework inside the application bundle. This way your application is ready for deployment, with its source code hidden because it is pre-compiled.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ macruby_deploy 
Usage: macruby_deploy [options] application-bundle
        --compile                    Compile the bundle source code
        --embed                      Embed MacRuby inside the bundle
        --no-stdlib                  Do not embed the standard library
    -v, --version                    Display the version
&lt;/pre&gt;
&lt;p&gt;These functionalities are also available as Xcode targets, a few mouse clicks away.&lt;/p&gt;
&lt;h3&gt;DTrace Probes&lt;/h3&gt;
&lt;p&gt;DTrace static probes have been added to the VM, providing the exact same support as MacRuby 0.4.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/DTrace&quot;&gt;DTrace&lt;/a&gt; is a powerful tracing facility available since Leopard which allows you to trace the MacRuby runtime of any running application, in development or production.&lt;/p&gt;
&lt;p&gt;MacRuby ships with a few DTrace example scripts. Here is one which prints some information regarding objects collected by the GC at a given time.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ sudo dtrace -qs sample-macruby/DTrace/collected_objects64.d -p 72593
Target pid: 72593

^C

                                             CLASS       COUNT     
--------------------------------------------------------------------------------
                     __NSFastEnumerationEnumerator       100       
                                            Method       101       
                                      CommonLogger       102       
                                        NSCFNumber       200       
                                              Proc       202       
                                        ByteString       203       
                                          CTParser       204       
                                              Time       204       
                                  NSCFCharacterSet       400       
                              NSCheapMutableString       404       
                                      NSPathStore2       606       
                                          NSCFData       612       
                                    NSCFDictionary       1204      
                                         RubyArray       2434      
                                        NSCFString       21240     
&lt;/pre&gt;</description>
<pubDate>2009-11-17T13:13:23-08:00</pubDate>
<guid>http://macruby.org/blog/2009/11/17/macruby05b2.html</guid>
</item>
<item>
<title>MacRuby 0.5 beta 1</title>
<link>http://macruby.org/blog/2009/10/07/macruby05b1.html</link>
<description>&lt;p&gt;After several months of development we are very glad to announce the first beta release of MacRuby 0.5. As this release has very ambitious goals we will go through a few intermediate releases before shipping the final 0.5.&lt;/p&gt;
&lt;p&gt;You can download it from &lt;a href=&quot;http://www.macruby.org/files/MacRuby%200.5%20beta%201.zip&quot;&gt;here&lt;/a&gt;. Please note that this package is for Intel machines running Mac OS X v10.6 or higher.&lt;/p&gt;
&lt;p&gt;Remember that this is a development version of MacRuby provided for testing and experimentation purposes only. Even if a few things are quite stable, others are still under development. Please give it a try and &lt;a href=&quot;http://www.macruby.org/contact-us.html&quot;&gt;report us&lt;/a&gt; any problem you find, to make sure the final release will be great.&lt;/p&gt;
&lt;p&gt;A lot of progress has been made in this version.  Here is a summary of what&amp;#8217;s new.&lt;/p&gt;
&lt;h3&gt;Compilation&lt;/h3&gt;
&lt;p&gt;MacRuby was based on YARV, the original Ruby 1.9 virtual machine. Two things worried us about YARV: the lack of machine code compilation and the &lt;a href=&quot;http://en.wikipedia.org/wiki/Global_Interpreter_Lock&quot;&gt;global interpreter lock&lt;/a&gt; (GIL) preventing true concurrency. Since concurrency and machine code compilation are so critical to performance, we decided to write a replacement, a very ambitious target.&lt;/p&gt;
&lt;p&gt;The new MacRuby 0.5 runtime is built upon &lt;a href=&quot;http://llvm.org&quot;&gt;LLVM&lt;/a&gt;, a compiler infrastructure also sponsored by Apple. Thanks to LLVM, MacRuby is able to transform the Ruby abstract syntax tree (AST) from the parser directly into highly optimized machine code. MacRuby supports both &lt;a href=&quot;http://en.wikipedia.org/wiki/Just-in-time_compilation&quot;&gt;Just in Time&lt;/a&gt; (JIT) and &lt;a href=&quot;http://en.wikipedia.org/wiki/AOT_compiler&quot;&gt;Ahead of Time&lt;/a&gt; (AOT) compilation. The JIT mode will compile down the code at runtime, and the AOT mode will allow you to save on disk the compilation result. AOT compilation makes MacRuby a true Ruby compiler.&lt;/p&gt;
&lt;p&gt;MacRuby ships with the macrubyc command line utility, which is an interface to the AOT compiler. It can produce a &lt;a href=&quot;http://en.wikipedia.org/wiki/Mach-O&quot;&gt;Mach-O&lt;/a&gt; compatible object file (.o) out of a given Ruby source file. You can also assemble multiple files to get a standalone executable binary ready for deployment. This can be used to compile a MacRuby Cocoa application, dramatically improving its startup time while making sure the original Ruby source code is not readable.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ echo &quot;p ARGV.map { |x| x.to_i }.inject(0) { |x, y| x + y }&quot; &amp;gt; t.rb
$ macrubyc t.rb -o t
$ file t
t: Mach-O 64-bit executable x86_64
$ ./t 1 2 3 4 5
15
&lt;/pre&gt;
&lt;p&gt;We also introduced a mode that generates a dynamic shared library out of a Ruby source file, using the new .rbo extension. MacRuby at runtime will #require these .rbo files in priority. We pre-compiled parts of the standard library using this technique.&lt;/p&gt;
&lt;h3&gt;Concurrency&lt;/h3&gt;
&lt;p&gt;The new MacRuby 0.5 runtime is designed to support concurrent execution, allowing a MacRuby program to use more than one CPU core at a time and multiple threads to call into MacRuby at the same time. This new design is critical as we enter the multicore age.&lt;/p&gt;
&lt;p&gt;MacRuby uses native POSIX threads to represent the Thread class. Every native thread has its own VM instance, which allows multiple threads to dispatch code without interrupting others. The &lt;a href=&quot;http://www.opensource.apple.com/source/autozone/autozone-77.1/README.html?f=text&quot;&gt;MacRuby garbage collector&lt;/a&gt; is now able to finalize objects on separate threads, preventing pauses in execution during GC.&lt;/p&gt;
&lt;p&gt;MacRuby ships with an API for &lt;a href=&quot;http://libdispatch.macosforge.org/&quot;&gt;Grand Central Dispatch&lt;/a&gt; (GCD), a multicore computing functionality present in Mac OS 10.6, Snow Leopard. The significant advantage of GCD is not having to deal with threading directly. With our new GCD API you set up queues and dispatch Ruby blocks to them. GCD will handle executing those blocks on system threads, ensuring all your CPU cores are used.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
waiting_chairs = Dispatch::Queue.new('com.apple.waiting_chairs')
semaphore = Dispatch::Semaphore.new(3)
index = -1
while true
  index += 1
  if semaphore.wait(Dispatch::TIME_NOW) != 0
    puts &quot;Customer turned away #{index}&quot;
    next
  end
  waiting_chairs.dispatch do
    semaphore.signal
    puts &quot;Shave and a haircut #{index}&quot;
  end
end
&lt;/pre&gt;
&lt;h3&gt;Optimizations&lt;/h3&gt;
&lt;p&gt;MacRuby 0.5 includes significant runtime-level optimizations, such as a much faster method dispatcher, cheap local variables, fast instance variable access, zero-cost DWARF exceptions, immediate floating point types, and many more.&lt;/p&gt;
&lt;p&gt;At the core classes level, we introduced a ByteString class to properly handle raw data, rewrote the IO layer for better stability and performance, and introduced a new implementation of Array, optimized for handling Ruby immediate types.&lt;/p&gt;
&lt;p&gt;Most of these optimizations were implemented after profiling a large MacRuby application.&lt;/p&gt;
&lt;h3&gt;Cocoa Development&lt;/h3&gt;
&lt;p&gt;We re-implemented the C and Objective-C support of 0.4 in this new release. An application written for 0.4 should continue to work on 0.5, but you should see it execute faster.&lt;/p&gt;
&lt;p&gt;In 0.4 we used to use the &lt;a href=&quot;http://sourceware.org/libffi/&quot;&gt;libffi&lt;/a&gt; library to call C and Objective-C functions and to create closures. RubyCocoa is also based on libffi. While libffi is a great library to use for external dispatch, it has definite performance limitations. In 0.5 MacRuby generates stubs using LLVM at runtime, enabling much better performance (from 3 to 4 times faster).&lt;/p&gt;
&lt;h3&gt;Compatibility&lt;/h3&gt;
&lt;p&gt;We want MacRuby to be as compatible as possible with existing Ruby programs. We have been working hard on MacRuby to make sure it behaves like MRI 1.9.&amp;#215;.&lt;/p&gt;
&lt;p&gt;Like most other Ruby implementations, we are now using the &lt;a href=&quot;http://rubyspec.org&quot;&gt;RubySpec&lt;/a&gt; project to check our compatibility. RubySpec is a set of executable specifications about the Ruby language and is maintained by the community.&lt;/p&gt;
&lt;p&gt;At the time of this writing, MacRuby passes about 91% of the language specs, 80% of the core specs and 72% of the library specs. Our objective is to pass as many RubySpecs as possible.&lt;/p&gt;
&lt;p&gt;Thanks to a better compatibility, MacRuby is able to run complex Ruby programs like irb, rake, rubygems, and more. Full compatibility is still a work in progress, but we expect MacRuby to run many more Ruby programs in the near future as we fix bugs and implement missing features.&lt;/p&gt;</description>
<pubDate>2009-10-07T18:35:52-07:00</pubDate>
<guid>http://macruby.org/blog/2009/10/07/macruby05b1.html</guid>
</item>
<item>
<title>An Experimental MacRuby</title>
<link>http://macruby.org/blog/2009/03/28/experimental-branch.html</link>
<description>&lt;p&gt;As you might have noticed, MacRuby 0.4 has just been released a few days ago. It&amp;#8217;s now time to focus on the next release, 0.5, which will be principally dedicated to performance.&lt;/p&gt;
&lt;h3&gt;New Virtual Machine&lt;/h3&gt;
&lt;p&gt;A new virtual machine based on the &lt;a href=&quot;http://llvm.org/&quot;&gt;LLVM compiler infrastructure&lt;/a&gt; has been developed and integrated as a replacement for YARV.&lt;/p&gt;
&lt;p&gt;The new VM transforms the abstract source tree (AST) directly from the parser into LLVM&amp;#8217;s intermediate representation (IR), which is then compiled into optimized machine code.  A number of other key optimizations have also been completed, such as fast fixnum arithmetic, cached method dispatch, zero-cost IA64 exceptions, fast instance variable access, constants caching, fast break/next, cheap local variables, tail call optimization and much more.&lt;/p&gt;
&lt;p&gt;While the amount of work remaining is significant, the compiler is already able to compile most of the Ruby syntax and the new runtime is mostly complete.  Early performance measurements are also very promising, with substantial room for improvement remaining.&lt;/p&gt;
&lt;h3&gt;New IO Subsystem&lt;/h3&gt;
&lt;p&gt;A new IO implementation based on &lt;a href=&quot;http://developer.apple.com/documentation/CoreFOundation/Reference/CFStreamConstants/Reference/reference.html&quot;&gt;CoreFoundation streams&lt;/a&gt; is under active development. The objective of this work is to provide a cleaner and faster implementation of the various IO operations; additionally, we will be able to perform asynchronous operations through the principal run loop.&lt;/p&gt;
&lt;p&gt;A ByteString class which silently inherits from String has been introduced and is now used as the return value of all IO operations. Its backing store is a &lt;a href=&quot;http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFMutableDataRef/Reference/reference.html&quot;&gt;CFMutableDataRef&lt;/a&gt;, which integrates better with the new IO subsystem and offers substantially better performance.&lt;/p&gt;
&lt;h3&gt;RubySpec Integration&lt;/h3&gt;
&lt;p&gt;Performance without compatibility is, of course, meaningless. We have therefore integrated the &lt;a href=&quot;http://rubyspec.org/&quot;&gt;RubySpec&lt;/a&gt; project and are aiming to pass all the specifications.&lt;/p&gt;
&lt;p&gt;The current experimental branch is already able to pass most of the language specifications and will be a standard part of our regression test suite. We are also actively working on upgrading the specifications to match the Ruby 1.9 behaviors.&lt;/p&gt;
&lt;h3&gt;Want to Help?&lt;/h3&gt;
&lt;p&gt;If you want to help or simply give the new changes a try, everything is on the experimental SVN branch.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ svn co http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental macruby-experimental
&lt;/pre&gt;
&lt;p&gt;Please make sure to read the README file for information regarding requirements, dependencies and build instructions. Do not hesitate to contact us if you need more info!&lt;/p&gt;</description>
<pubDate>2009-03-28T05:24:51-07:00</pubDate>
<guid>http://macruby.org/blog/2009/03/28/experimental-branch.html</guid>
</item>
<item>
<title>MacRuby 0.4</title>
<link>http://macruby.org/blog/2009/03/09/macruby-0.4.html</link>
<description>&lt;p&gt;After several months of development and some slight delays, MacRuby 0.4 is now available. Get it here while it&amp;#8217;s still hot!&lt;/p&gt;
&lt;p&gt;This is quite an important release that brings new features and fixes several problems. The changes are too numerous to be all mentioned, so here is a selection of the most interesting ones.&lt;/p&gt;
&lt;h3&gt;Threaded GC&lt;/h3&gt;
&lt;p&gt;The MacRuby garbage collector is now running in multi-threaded mode by default. That means that MacRuby will always do garbage collections on a separate thread and therefore not interrupt the program&amp;#8217;s flow.&lt;/p&gt;
&lt;h3&gt;Full 64-bit Support&lt;/h3&gt;
&lt;p&gt;MacRuby is now fully working in both Intel 32-bit and 64-bit modes. If you are running a recent Mac chances are that it is 64-bit and MacRuby will run faster on it. This is mainly due to the fact that the underlying infrastructure has been significantly improved for 64-bit processors.&lt;/p&gt;
&lt;h3&gt;DTrace Probes&lt;/h3&gt;
&lt;p&gt;DTrace probes have been added to the core of the interpreter. You can now trace various things such as method calls or exceptions. All of that can be done on any MacRuby processes in the system.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
provider macruby {
    probe insn__entry(char *insnname, char *sourcefile, int sourceline);
    probe insn__return(char *insnname, char *sourcefile, int sourceline);
    probe method__entry(char *classname, char *methodname, char *sourcefile, int sourceline);
    probe method__return(char *classname, char *methodname, char *sourcefile, int sourceline);
    probe raise(char *classname, char *sourcefile, int sourceline);
    probe rescue(char *sourcefile, int sourceline);
};
&lt;/pre&gt;
&lt;p&gt;DTrace is a very powerful tool that has proven to be extremely useful when debugging live applications. MacRuby ships with several DTrace scripts in &lt;a href=&quot;http://www.macruby.org/trac/browser/MacRuby/trunk/sample-macruby/DTrace&quot;&gt;/Developer/Examples/Ruby/MacRuby/DTrace&lt;/a&gt; to profile various things such as method count, duration or even objects collected by the GC.&lt;/p&gt;
&lt;h3&gt;Runtime Objective-C API&lt;/h3&gt;
&lt;p&gt;MacRuby now exposes &lt;a href=&quot;http://www.macruby.org/trac/browser/MacRuby/trunk/include/ruby/objc.h&quot;&gt;an Objective-C API&lt;/a&gt; that can be used to control the runtime from a pure Cocoa environment.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ cat hello_macruby.m 
#import &amp;lt;Foundation/Foundation.h&amp;gt;
#import &amp;lt;MacRuby/MacRuby.h&amp;gt;

int main(void) {
    id proc = [[MacRuby sharedRuntime] evaluateString:@&quot;proc { |x| puts \&quot;hello #{x}\&quot;}&quot;];
    [proc performRubySelector:@selector(call:) withArguments:@&quot;MacRuby&quot;];
    return 0;
}
$ gcc hello_macruby.m -o hello_macruby -framework Foundation -framework MacRuby -fobjc-gc
$ ./hello_macruby 
hello MacRuby
&lt;/pre&gt;
&lt;p&gt;It should be helpful if you are working on an Objective-C Cocoa application and are considering using MacRuby to either implement new functionalities or to provide a scripting interface to your native objects.&lt;/p&gt;
&lt;h3&gt;New Xcode Templates&lt;/h3&gt;
&lt;p&gt;A &amp;#8220;MacRuby Core Data Application&amp;#8221; template is now available, as well as an &amp;#8220;Embed MacRuby&amp;#8221; target. The latter can be used to embed MacRuby.framework inside your application bundle. Embedding the framework allows you to distribute your application to users and not require them to install MacRuby.&lt;/p&gt;
&lt;h3&gt;A Better HotCocoa&lt;/h3&gt;
&lt;p&gt;HotCocoa is a thin, idiomatic Ruby layer that sits above Cocoa and other frameworks. It was introduced in MacRuby 0.3 and it has been significantly improved in 0.4.&lt;/p&gt;
&lt;p&gt;New mappings for XML parser, KVO array/set accessors, property lists and more AppKit components were added as well as lots of bug fixes and improvements.&lt;/p&gt;
&lt;p&gt;A &amp;#8220;deploy&amp;#8221; task was added to the project&amp;#8217;s Rakefile. This new task prepares an application for deployment by embedding the MacRuby runtime inside its bundle (similar to what the Xcode&amp;#8217;s Embed MacRuby target does). Once the &amp;#8220;macrake deploy&amp;#8221; task is complete, you can share your .app with friends who do not have MacRuby installed on their machine.&lt;/p&gt;
&lt;p&gt;But the most interesting change is probably the new graphics layer, called &lt;a href=&quot;http://hcg.drtoast.com/&quot;&gt;HotCocoa::Graphics&lt;/a&gt;. It provides a simple object-oriented interface into the power of Mac OS X&amp;#8217;s Core Graphics and Core Image drawing libraries.&lt;/p&gt;
&lt;h3&gt;Misc Changes&lt;/h3&gt;
&lt;p&gt;Over the list of minor changes, Set has been reimplemented on top of NSSet and NSNumber implements the Numeric methods. Finally, the standard library was updated to Ruby 1.9.1&amp;#8217;s version.&lt;/p&gt;
&lt;h3&gt;Caveat Lector&lt;/h3&gt;
&lt;p&gt;While MacRuby 0.4 turns out to be pretty stable when it comes to Cocoa development, there are still a few problems with C extensions, RubyGems and Ruby IOs. We recommend to use the corresponding Cocoa APIs (when they exist) in the meantime we work on these issues.&lt;/p&gt;
&lt;p&gt;We hope that you will enjoy this release. Please let us know if you find any problems.&lt;/p&gt;
&lt;p&gt;Stay tuned for more details about the next release: 0.5, which will be focusing on performance.&lt;/p&gt;</description>
<pubDate>2009-03-09T05:24:51-07:00</pubDate>
<guid>http://macruby.org/blog/2009/03/09/macruby-0.4.html</guid>
</item>
<item>
<title>Developing Cocoa Applications Using MacRuby</title>
<link>http://macruby.org/blog/2008/10/17/developing_cocoa.html</link>
<description>&lt;p&gt;The Apple Developer Connection (&lt;span class=&quot;caps&quot;&gt;ADC&lt;/span&gt;) website is now featuring an article about MacRuby, titled &lt;a href=&quot;http://developer.apple.com/mac/articles/scriptingautomation/cocoaappswithmacruby.html&quot;&gt;Developing Cocoa Applications Using MacRuby&lt;/a&gt;. This article will introduce you to MacRuby and guide you through the process of writing a Cocoa application with it.&lt;/p&gt;
&lt;p&gt;Enjoy, and do not hesitate to contact us if you have any question!&lt;/p&gt;</description>
<pubDate>2008-10-16T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/10/17/developing_cocoa.html</guid>
</item>
<item>
<title>MacRuby 0.3</title>
<link>http://macruby.org/blog/2008/09/08/macruby_0.3.html</link>
<description>&lt;p&gt;It is a great pleasure to announce the immediate availability of MacRuby 0.3! We have been working very hard on this release for several months and, while it&amp;#8217;s still a developer release, we hope that you will give it a try. Get it while it&amp;#8217;s still hot!&lt;/p&gt;
&lt;p&gt;First of all, MacRuby now ships with a core library called HotCocoa, something which greatly simplifies Cocoa programming while also using simple Ruby idioms. Rich Kilmer is the man behind this amazing work. You will find several examples in &lt;a href=&quot;http://www.macruby.org/trac/browser/MacRuby/tags/0.3/sample-macruby/HotCocoa&quot;&gt;/Developer/Examples/Ruby/MacRuby/HotCocoa&lt;/a&gt;, and some initial bits of documentation in &lt;a href=&quot;http://www.macruby.org/trac/wiki/HotCocoa&quot;&gt;http://www.macruby.org/trac/wiki/HotCocoa&lt;/a&gt; (which will be improved very soon).&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;hotcocoa&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
include &lt;span class=&quot;co&quot;&gt;HotCocoa&lt;/span&gt;
application &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |app|
  window &lt;span class=&quot;sy&quot;&gt;:size&lt;/span&gt; =&amp;gt; [&lt;span class=&quot;i&quot;&gt;100&lt;/span&gt;, &lt;span class=&quot;i&quot;&gt;50&lt;/span&gt;] &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |win|
    b = button &lt;span class=&quot;sy&quot;&gt;:title&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Hello&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
    b.on_action { puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;World!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; }
    win &amp;lt;&amp;lt; b
  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Another big change in the method dispatcher, which is now entirely based on the Objective-C runtime. MacRuby is now using the Objective-C runtime to implement the Ruby class semantics and also to dispatch pure Ruby methods. This is an important change because it simplifies a lot the core implementation and also eliminates ambiguities between both worlds. Performance wise, we should be as performant as yarv:  Faster in some cases, slower in others.&lt;/p&gt;
&lt;p&gt;We also support Interface Builder in this release. You can define classes, outlets and actions in a MacRuby Xcode project and they will automatically appear in Interface Builder. We have a new Ruby metadata parser that works for both RubyCocoa and MacRuby files. The parser is written in MacRuby and uses the amazing ripper extension that comes with it to extract the parser tokens.&lt;/p&gt;
&lt;p&gt;Finally, of course, lots of bugs were fixed. We now have a pretty good Cocoa support and can run most of the &lt;a href=&quot;http://limechat.net/&quot;&gt;LimeChat&lt;/a&gt; application (which is currently being ported from RubyCocoa).  We also re-implemented the &lt;a href=&quot;http://weblog.bignerdranch.com/?p=23&quot;&gt;PagePacker&lt;/a&gt; application from Objective-C, which now ships &lt;a href=&quot;http://www.macruby.org/trac/browser/MacRuby/tags/0.3/sample-macruby/PagePacker&quot;&gt;as an example&lt;/a&gt; in the MacRuby distribution.  On the pure Ruby side of things, a lot of bugs have been fixed and we are now able to run some commands of RubyGems. Installing simple gems should work. Don&amp;#8217;t expect MacRuby to run Rails yet, though!&lt;/p&gt;
&lt;p&gt;MacRuby is progressively turning more stable with every release. Please give it a try and report any problem you find!  If you want to join the project and help, volunteers are also greatly welcome!&lt;/p&gt;</description>
<pubDate>2008-09-07T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/09/08/macruby_0.3.html</guid>
</item>
<item>
<title>Ruby Changes in 10.5.4 Update</title>
<link>http://macruby.org/blog/2008/06/30/ruby_changes.html</link>
<description>&lt;p&gt;Mac OS X 10.5.4 has just been released, addressing the &lt;a href=&quot;http://www.ruby-lang.org/en/news/2008/06/20/arbitrary-code-execution-vulnerabilities/&quot;&gt;latest Ruby security problems&lt;/a&gt; discovered by Apple&amp;#8217;s product security team, and also fixing the &lt;a href=&quot;http://www.ruby-forum.com/topic/154556&quot;&gt;getaddrinfo regression&lt;/a&gt;, that was introduced in 10.5.3 and breaking DRb.&lt;/p&gt;
&lt;p&gt;Please enjoy and do not hesitate to &lt;a href=&quot;http://bugreporter.apple.com/&quot;&gt;contact us&lt;/a&gt; if you discover regressions, and we will try to fix them as soon as possible.&lt;/p&gt;</description>
<pubDate>2008-06-29T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/06/30/ruby_changes.html</guid>
</item>
<item>
<title>New Build System, Faster Objective-C Dispatcher, Screencast</title>
<link>http://macruby.org/blog/2008/06/16/new_build_system.html</link>
<description>&lt;p&gt;MacRuby trunk got a new build system, entirely written with &lt;a href=&quot;http://rake.rubyforge.org/&quot;&gt;Rake&lt;/a&gt;. We managed to replace the previous autotools-based build system with a 570 lines of code Rakefile (which can still be refactored). We didn&amp;#8217;t really need autotools since MacRuby aims to be installed on only one platform: Mac OS X. Maintaining the autotools files were really difficult, and we are very glad to now have a pure-Ruby build script.&lt;/p&gt;
&lt;p&gt;Building and installing MacRuby is now very simple:&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ rake
$ sudo rake install
&lt;/pre&gt;
&lt;p&gt;This will build and install MacRuby in /Library/Frameworks/MacRuby.framework, executable symbolic links in /usr/local/bin (with a &amp;#8220;mac&amp;#8221; prefix, for example &amp;#8220;macruby&amp;#8221;), Xcode templates and sample code.&lt;/p&gt;
&lt;p&gt;To see the list of all tasks;&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ rake -T
(in /Volumes/Data/src/MacRuby)
rake all                   # Build MacRuby and extensions
rake clean                 # Clean local and extension build files
rake clean:ext             # Clean extension build files
rake clean:local           # Clean local build files
rake config_h              # Create config.h
rake default               # Same as all
rake extensions            # Build extensions
rake framework:info_plist  # Create the plist file for the framework
rake framework:install     # Install the framework
rake install               # Same as framework:install
rake macruby               # Same as macruby:build
rake macruby:build         # Build MacRuby
rake macruby:dylib         # Build dynamic libraries for MacRuby
rake macruby:static        # Build static libraries for MacRuby
rake miniruby              # Create miniruby
rake objects               # Build known objects
rake rbconfig              # Create config file
rake sample_test           # Run the sample tests
rake test                  # Same as sample_test
&lt;/pre&gt;
&lt;p&gt;Also, MacRuby trunk has a faster Objective-C dispatcher. Around 4 times faster that MacRuby 0.2 (and way faster than RubyCocoa). This was possible by fixing bugs in the dispatcher and also cache some of the runtime information.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s consider the following Objective-C class.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ cat dummy.m
#import &amp;lt;Foundation/Foundation.h&amp;gt;

@interface Dummy : NSObject
@end

@implementation Dummy

- (id)doSomething
{
   return @&quot;&quot;; 
}

- (id)doSomethingWith:(id)value
{
    return value;
}

@end

void Init_dummy (void) {}
&lt;/pre&gt;
&lt;p&gt;We can build it as a Ruby extension.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ gcc dummy.m -o dummy.bundle -framework Foundation -dynamiclib -fobjc-gc&quot;
&lt;/pre&gt;
&lt;p&gt;Then, test calling the methods. First, the doSomething method, which is a very simple case.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ ruby start.rb ruby -v -r osx/foundation -I. -r dummy -e &quot;include OSX; o = Dummy.new; 1_000_000.times { o.doSomething }&quot;
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
    5.295735
    5.290816
    5.28286
$ ../miniruby02 -v -I. -r dummy -e &quot;o = Dummy.new; 1_000_000.times { o.doSomething }&quot;
MacRuby version 0.2 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    2.977553
    2.98855
    2.984585
$ ../miniruby -v -I. -r dummy -e &quot;o = Dummy.new; 1_000_000.times { o.doSomething }&quot;
MacRuby version 0.3 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    0.639648
    0.65196
    0.644522
&lt;/pre&gt;
&lt;p&gt;Then, the doSomethingWith: method, a bit more complicated because one argument is passed, so both RubyCocoa and MacRuby are using libffi to call it.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ ruby -v -r osx/foundation -I. -r dummy -e &quot;include OSX; o = Dummy.new; o2 = 'foo'; 1_000_000.times { o.doSomethingWith(o2) }&quot;
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
    13.981403
    13.943761
    13.936082
$ ../miniruby02 -v -I. -r dummy -e &quot;o = Dummy.new; o2 = 'foo'; 1_000_000.times { o.doSomethingWith(o2) }&quot;
MacRuby version 0.2 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    7.267144
    7.210777
    7.267988
$ ../miniruby -v -I. -r dummy -e &quot;o = Dummy.new; o2 = 'foo'; 1_000_000.times { o.doSomethingWith(o2) }&quot;
MacRuby version 0.3 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    1.239323
    1.259157
    1.246987
&lt;/pre&gt;
&lt;p&gt;These are very premature results, we expect to continue reducing the time spent in the dispatcher, in the near future, and hopefully to make it twice faster.&lt;/p&gt;
&lt;p&gt;On a side note, Konrad M. Lawson was kind enough to generate a &lt;a href=&quot;http://foolsworkshop.com/rubycocoa/2008/06/macruby-tutorial&quot;&gt;very nice screencast of MacRuby&lt;/a&gt; demonstrating the Xcode/IB integration. Thanks Konrad!&lt;/p&gt;</description>
<pubDate>2008-06-15T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/06/16/new_build_system.html</guid>
</item>
<item>
<title>MacRuby 0.2</title>
<link>http://macruby.org/blog/2008/06/06/macruby_0.2.html</link>
<description>&lt;p&gt;After 3 months of development, here comes the second release of MacRuby, 0.2! Check it out while it&amp;#8217;s hot!&lt;/p&gt;
&lt;p&gt;This is an important release which addresses many bugs but also re-implements parts of the runtime using the &lt;a href=&quot;http://developer.apple.com/corefoundation/&quot;&gt;CoreFoundation&lt;/a&gt; framework.&lt;/p&gt;
&lt;p&gt;In MacRuby 0.2, all strings, arrays and hashes are now native Cocoa types, represented by NSString, NSArray and NSDictionary objects, respectively.&lt;/p&gt;
&lt;p&gt;The entire String, Array and Hash interface was rewritten on top of the Cocoa equivalents using the powerful CoreFoundation framework.&lt;/p&gt;
&lt;p&gt;The previous implementation, inherited from MRI, is not used anymore. The rationale behind this change is simple:&lt;/p&gt;
&lt;p&gt;It is no longer necessary to convert Ruby primitive types to Cocoa or vice-versa. For example, a String created in MacRuby can be passed as is, without conversion, to an underlying C or Objective-C API that expects an NSString. Similarly, any method of the Ruby String class can be performed on an NSString that comes from Objective-C.&lt;/p&gt;
&lt;p&gt;Interestingly, the CoreFoundation implementation that MacRuby now uses has proven itself to be stable and performs quite well, even this early in the implementation process.&lt;/p&gt;
&lt;p&gt;We did not work on any performance improvements for MacRuby 0.2 (we will address performance in the next upcoming release), but we noticed some dramatic performance gains in some areas nonetheless.&lt;/p&gt;
&lt;p&gt;Inserting elements in an array is faster in MacRuby than the original 1.9 implementation, for example, mostly because CFArray switches on the fly its data structure to an implementation that performs well according to the current number of elements.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
a=[]; 100_000.times { |i| a.insert(0, i) }
MacRuby version 0.2 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    0.326057
    0.318714
    0.314731
ruby 1.9.0 (2008-06-03 revision 16762) [i686-darwin9.0.0]
    4.308484
    4.382623
    4.36368
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
    4.608796
    4.595334
    4.581045
&lt;/pre&gt;
&lt;p&gt;Regarding hashes, searching for a specific value (which isn&amp;#8217;t something that is typically done) is shown to be faster. k&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
h = Hash[*(1..10000).to_a]; 10000.times { |i| h.has_value?(i) }
MacRuby version 0.2 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    0.965304
    0.955293
    0.950316
ruby 1.9.0 (2008-06-03 revision 16762) [i686-darwin9.0.0]
    3.790461
    3.804271
    3.815217
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
    4.225632
    4.225457
    4.239244
&lt;/pre&gt;
&lt;p&gt;And to finish with strings, it turns out that manipulations on multi-byte strings are faster in MacRuby than 1.9.&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ cat t3.rb 
# -*- coding: utf-8 -*-
s = &quot;わたしはロランです。&quot; * 2000
s.length.times { |i| s[i] }
$ ruby b.rb t3.rb 
MacRuby version 0.2 (ruby 1.9.0 2008-06-03) [universal-darwin9.0]
    0.180019
    0.180165
    0.177425
ruby 1.9.0 (2008-06-03 revision 16762) [i686-darwin9.0.0]
    1.624943
    1.633502
    1.62767
&lt;/pre&gt;
&lt;p&gt;Speaking of strings, since every of them is now a CFString, they get for free features that weren&amp;#8217;t present in the original 1.9 implementation, such as ICU transformations for example:&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
$ cat t3.rb
puts &quot;watashiha&quot;.transform('Latin-Hiragana') +
     &quot;lauren&quot;.transform('Latin-Katakana') +
     &quot;desu.&quot;.transform('Latin-Hiragana')
$ macruby -v t3.rb
MacRuby version 0.2 (ruby 1.9.0 2008-05-17) [universal-darwin9.0]
わたしはラウレンです。
&lt;/pre&gt;
&lt;p&gt;MacRuby is still slower in many cases, including very important ones such as objects allocation and methods dispatch. There are also too many areas in String, Array and Hash where we perform much less well than we should.&lt;/p&gt;
&lt;p&gt;We plan to address this in the next release (0.3) as well as many other things, so stay tuned!&lt;/p&gt;</description>
<pubDate>2008-06-05T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/06/06/macruby_0.2.html</guid>
</item>
<item>
<title>More RubyCocoa Projects in the Wild</title>
<link>http://macruby.org/blog/2008/05/27/rubycocoa_projects_wild.html</link>
<description>&lt;p&gt;Very recently some new projects using &lt;a href=&quot;http://rubycocoa.sf.net/&quot;&gt;RubyCocoa&lt;/a&gt; were released to the public.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.pimsnel.com/timetoticket/Home.html&quot;&gt;TimeToTicket&lt;/a&gt;, a tool to report your working hours in the RedMine project management system.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://inexdo.com/CocoaNav&quot;&gt;CocoaNav&lt;/a&gt;, an application to elegantly browse frameworks and classes. Very cool animations.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.dribin.org/dave/blog/archives/2008/05/24/osx_trash&quot;&gt;osx_trash&lt;/a&gt;, a command-line tool to easily manipulate the Mac OS X Finder&amp;#8217;s trash.&lt;/p&gt;
&lt;p&gt;And, it&amp;#8217;s hard to not mention &lt;a href=&quot;http://github.com/Caged/gitnub/wikis&quot;&gt;GitNub&lt;/a&gt;, a desktop frontend to the git source control management system. This isn&amp;#8217;t really a new project, but it&amp;#8217;s starting to be popular in the development community.&lt;/p&gt;
&lt;p&gt;This really demonstrates that RubyCocoa is being adopted by more people, and more importantly, Ruby as a language to write Mac OS X applications. And &lt;a href=&quot;/documentation/why-macruby.html&quot;&gt;the future&lt;/a&gt; is not that far now!&lt;/p&gt;</description>
<pubDate>2008-05-26T21:00:00-07:00</pubDate>
<guid>http://macruby.org/blog/2008/05/27/rubycocoa_projects_wild.html</guid>
</item>
</channel>
</rss>













