<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LolocoJr &#187; ruby</title>
	<atom:link href="http://www.railsguru.com/articles/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsguru.com</link>
	<description>Andy Lo-A-Foe&#039;s blog</description>
	<lastBuildDate>Thu, 21 Jul 2011 13:31:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Snow Leopard + MySQL + Ruby + 64-bit = #fail</title>
		<link>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/</link>
		<comments>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 12:08:16 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4618</guid>
		<description><![CDATA[Running into the following error after your Snow Leopard upgrade? uninitialized constant MysqlCompat::MysqlRes Then the following build line for the mysql gem might fix it for you: ARCHFLAGS="-arch i386 -arch x86_64" \ gem install --no-rdoc --no-ri mysql ]] \ -- &#8230; <a href="http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Running into the following error after your Snow Leopard upgrade?</p>
<pre>uninitialized constant MysqlCompat::MysqlRes</pre>
<p>Then the following build line for the mysql gem might fix it for you:</p>
<pre>ARCHFLAGS="-arch i386 -arch x86_64"  \</pre>
<pre>  gem install --no-rdoc --no-ri mysql ]] \</pre>
<pre>  -- --with-mysql-dir=/opt/local/lib/mysql5 \</pre>
<pre>  --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2010/07/09/snow-leopard-mysql-ruby-64-bit-fail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing new Ruby postgresql adapter on Leopard</title>
		<link>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/</link>
		<comments>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 12:04:51 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[postgresql ruby gem leopard]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4547</guid>
		<description><![CDATA[I need to fix a project which uses PostgreSQL. On a fresh Leopard install with postgresql 8.3 installed from ports I ran into this problem: $ sudo gem install pg Building native extensions.  This could take a while... ERROR:  Error &#8230; <a href="http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I need to fix a project which uses PostgreSQL. On a fresh Leopard install with postgresql 8.3 installed from ports I ran into this problem:</p>
<pre>$ sudo gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-pg:
ERROR: Failed to build gem native extension.</pre>
<p>The solution is quite simply. Just make sure pg_config can be found by the gem installer.</p>
<pre>$ mdfind pg_config|grep bin|uniq
/opt/local/lib/postgresql83/bin/pg_config</pre>
<p>In this case make sure /opt/local/lib/postgresql/bin is available in the path when executing the gem command</p>
<pre>$ PATH=/opt/local/lib/postgresql83/bin:$PATH sudo gem install pg</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/06/05/installing-new-ruby-postgresql-adapter-on-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typo -&gt; Mephisto -&gt; WordPress</title>
		<link>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/</link>
		<comments>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 16:19:01 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[mephisto]]></category>
		<category><![CDATA[typo]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/?p=4486</guid>
		<description><![CDATA[First I tried Typo, then Mephisto and now this blog is running WordPress. As a Ruby fan I really wanted to use Ruby everywhere, 2 years ago. I&#8217;m now at the point where I just want working stuff (kids will &#8230; <a href="http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>First I tried Typo, then Mephisto and now this blog is running WordPress. As a Ruby fan I really wanted to use Ruby everywhere, 2 years ago. I&#8217;m now at the point where I just want working stuff (kids will do that to you I guess). The migration from Mephisto to WordPress was very very smooth, thanks to <a href="http://jayunit.net/2008/04/16/mephisto-to-wordpress/" target="_blank">this excellent article</a>. The Mephisto version I was running was producing a Rails error based on some spam message which was posted. I really didn&#8217;t want to dig into the error and upgrading to the latest Mephisto was going to be quite a bit of work. All in all the switch to WordPress took about 2 hours in total, including customizing the theme a bit and making sure the old permalinks kept working. Cool!</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/01/21/typo-mephisto-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Passenger with RACK apps</title>
		<link>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/</link>
		<comments>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 18:16:42 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/11/17/pasenger-with-rack-app</guid>
		<description><![CDATA[I started converting various apps running on mongrel clusters over to Apache + Passenger. One component of our production system is implemented as as mongrel plugin so it kind of sucks tot keep mongrel around just for this part. The &#8230; <a href="http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I started converting various apps running on mongrel clusters over to Apache + Passenger. One component of our production system is implemented as as mongrel plugin so it kind of sucks tot keep mongrel around just for this part. The reason I&#8217;m looking to abandon mongrel is because it requires all sorts of crappy monitoring tools to keep working properly. Luckily Passenger implements a RACK adapter so converting the mongrel plugin to a full blown RACK app should allow us to host it righ inside Passenger as well.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2009/01/18/pasenger-with-rack-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passenger makes Apache relevant again</title>
		<link>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/</link>
		<comments>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 06:28:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[nginx apache rails passenger mongrel]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/10/11/passenger-makes-apache-relevant-again</guid>
		<description><![CDATA[After stearing clear of Apache2 for the last year for all production servers I&#8217;m now ready to give it another try, thanks to Phusion&#8217;s Passenger. I&#8217;ve grown really tired of setting up god scripts for all environments and fighting mongrel&#8217;s &#8230; <a href="http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After stearing clear of Apache2 for the last year for all production servers I&#8217;m now ready to give it another try, thanks to <a href="http://www.modrails.com" target="_blank">Phusion&#8217;s Passenger</a>. I&#8217;ve grown really tired of setting up god scripts for all environments and fighting mongrel&#8217;s pidfile suckage.</p>
<p>Far too many times have things failed because of a dead worker in the cluster or some stale or (even worse!) non-existent pidfiles on the system. Mongrel has served well, but it&#8217;s time to look for something better.</p>
<p>A typical setup I use is nginx as the front-end server doing all static content while a pack of mongrels is handling the Rails requests through reverse proxy. nginx is also very important for reproxying requests, where content is streamed from another internal server over the front facing servers. In most of the Rails app I&#8217;m writing I have to deal with very large files (audio, video) so reproxy is essential if you want to have any sort of performance on a reasonable budget. Since Apache2 lacks reproxy support (AFAIK, please prove me wrong!) I really want to keep nginx as the front-end server and then do the Rails handling with Apache2 + Passenger through reverse proxy.</p>
<p>I&#8217;ve come a cross <a href="http://blog.kovyrin.net/2006/05/18/nginx-as-reverse-proxy/" target="_blank">a couple</a> of <a href="http://wiki.joyent.com/accelerators:nginx_apache_proxy" target="_blank">posts</a> on this very topic.</p>
<p>I&#8217;ll be doing some heavy development and testing over the next couple of days with this setup, will post my findings&#8230;</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/10/11/passenger-makes-apache-relevant-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails&#8217; end_of_month fixed</title>
		<link>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/</link>
		<comments>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 11:26:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rails end_of_month]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/07/14/rails-end_of_month-fixed</guid>
		<description><![CDATA[In Rails 2.0.x the end_of_month now properly gives you the end of month e.g. Mon Jun 30 23:59:59 +0200 2008, instead of Mon Jun 30 00:00:00 +0200 2008, which was the case in Rails 1.2.x (see this previous post). Good &#8230; <a href="http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In Rails 2.0.x the end_of_month now properly gives you the end of month e.g. <strong>Mon Jun 30 23:59:59 +0200 2008</strong>, instead of <strong>Mon Jun 30 00:00:00 +0200 2008</strong>, which was the case in Rails 1.2.x (see <a target="_blank" href="http://www.railsguru.com/articles/2006/2/20/rails-end_of_month">this previous post</a>). Good thing I caught this, since it used to inside the Nota module of <a target="_blank" href="http://www.beldienst.nl">Beldienst</a>. We would be paying out the first of each month twice otherwise <img src='http://www.railsguru.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/06/01/rails-end_of_month-fixed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Massive memory leak in ruby-gettext 1.90.0</title>
		<link>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/</link>
		<comments>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/#comments</comments>
		<pubDate>Thu, 08 May 2008 19:38:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gettext leakage]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/10/27/massive-memory-leak-in-ruby-gettext-1-90-0</guid>
		<description><![CDATA[Just found out there&#8217;s a massive memory leak in ruby gettext 1.90.0, one of our applications started eating GBs of RAM after a couple of days in use. So If you&#8217;re using gettext for translating your Rails app take note! &#8230; <a href="http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just found out there&#8217;s a massive memory leak in ruby gettext 1.90.0, one of our applications started eating GBs of RAM after a couple of days in use. So If you&#8217;re using gettext for translating your Rails app take note! You can grab the <a href="http://rubyforge.org/scm/?group_id=855" target="_blank">current trunk</a> which has a fix for this.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/05/08/massive-memory-leak-in-ruby-gettext-1-90-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Side project: De TV Flat (KRO)</title>
		<link>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/</link>
		<comments>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 00:16:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tvflat rails project video streaming]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/04/30/side-project-de-tv-flat-kro</guid>
		<description><![CDATA[My first Rails 2.0.x project has been running in production for a couple of months now. It&#8217;s the website for KRO&#8217;s &#8220;De TV Flat&#8221;, a children/teens program airing every Saturday on dutch national television around 9am (channel Nederland 3) untill &#8230; <a href="http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
My first Rails 2.0.x project has been running in production for a couple of months now. It&#8217;s the website for KRO&#8217;s <a href="http://www.tvflat.kro.nl" target="_blank">&#8220;De TV Flat&#8221;</a>, a children/teens program airing every Saturday on dutch national television around 9am (channel Nederland 3) untill the beginning of summer. I&#8217;m very proud to actually get one of my projects on TV! The premise is basically &#8220;Youtube for kids&#8221; with the chance of getting your self-made video&#8217;s broadcasted on TV!
</p>
<p>
<img src="http://railsguru.com/assets/2008/4/30/tvflat.jpg" />
</p>
<p>
I really like the <a href="http://tvflat.nl/frontend/search?query=wvjhw" target="_blank">instructional video&#8217;s</a> made by the TVFlat crew, very  helpfull tips for creating your own video content.
</p>
<p>Technology used:</p>
<ul>
<li>Linux</li>
<li>Nginx HTTP server</li>
<li>Mongrel</li>
<li>MogileFS clustered storage</li>
<li>Rails 2.0.2</li>
<li>Merb 0.54 for critical code paths, beats Rails to a pulp when it comes to roundtrip times</li>
<li>Memcached</li>
<li>MySQL</li>
<li>Lucene</li>
<li>mplayer / ffmpeg / faac for transcoding, direct broadcast quality feeds are generated!</li>
<li>Flash video</li>
</ul>
<p>
Hope I can find some time later on to write a bit about the different parts.. anyway, <a href="http://www.tvflat.kro.nl" target="_blank">go check it out!</a></p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2008/04/30/side-project-de-tv-flat-kro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JRuby saves the day</title>
		<link>http://www.railsguru.com/articles/2007/11/29/jruby-saves-the-day/</link>
		<comments>http://www.railsguru.com/articles/2007/11/29/jruby-saves-the-day/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 11:19:00 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[jruby ruby drb java]]></category>

		<guid isPermaLink="false">http://www.railsguru.com/2008/09/24/jruby-saves-the-day</guid>
		<description><![CDATA[So I&#8217;m rewriting yet another subsystem which consists of a mismash of several languages and programmer ego&#8217;s (hardcore C being the largest one, aargh) to what else .. Ruby. Everythings going smoothly. Every line of Ruby code replaces about 10 &#8230; <a href="http://www.railsguru.com/articles/2007/11/29/jruby-saves-the-day/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
So I&#8217;m rewriting yet another subsystem which consists of a mismash of several languages and programmer ego&#8217;s (hardcore C being the largest one, aargh) to what else .. Ruby. Everythings going smoothly. Every line of Ruby code replaces about 10 lines of &#8220;put other language here&#8221; cruft. Life couldn&#8217;t be more beautiful. But then I hit the wall, the Java wall. Here I&#8217;m confronted with a full enterprisy Service Manager complete with dependencies on Java-only libs. Now what? I could rewrite the whole thing in Ruby. But then there would be 2 implementations of the same thing to maintain, not to mention reading through Java code, bad.</p>
<p>
Enter <strong>JRuby</strong>. Since the main code blob of this project is captured in a Mongrel plugin I thought about just deploying the whole of Mongrel on JRuby. Unfortunately JRuby Mongrel support was not there yet (<a href="http://mongrel.rubyforge.org/news.html" target="_blank">Mongrel 1.1</a> supports JRuby). So the next best thing was to build some kind bridge between JRuby and Ruby + Mongrel + Plugin. Distributed Ruby (DRb) is a perfect fit:
</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="c">#</span><tt>
</tt><span class="c"># server.rb (this)</span><tt>
</tt><span class="c"># jars/big-bad-service.jar</span><tt>
</tt><span class="c">#</span><tt>
</tt><span class="co">APP_ROOT</span> = <span class="co">File</span>.join(<span class="co">File</span>.dirname(<span class="pc">__FILE__</span>), <span class="s"><span class="dl">'</span><span class="k">.</span><span class="dl">'</span></span>)<tt>
</tt><tt>
</tt>require <span class="s"><span class="dl">'</span><span class="k">java</span><span class="dl">'</span></span><tt>
</tt>require <span class="s"><span class="dl">'</span><span class="k">drb</span><span class="dl">'</span></span><tt>
</tt><tt>
</tt>require <span class="s"><span class="dl">&quot;</span><span class="il"><span class="dl">#{</span><span class="co">APP_ROOT</span><span class="dl">}</span></span><span class="k">/jars/big-bad-service.jar</span><span class="dl">&quot;</span></span><tt>
</tt><tt>
</tt><span class="co">BigBadService</span> = com.blah.<span class="co">BigBadService</span><tt>
</tt><tt>
</tt><span class="r">class</span> <span class="cl">JRubyServer</span><tt>
</tt>  <span class="r">def</span> <span class="fu">initialize</span><tt>
</tt>    <span class="iv">@bbs</span> = <span class="co">BigBadService</span>.new<tt>
</tt>    <span class="iv">@bbs</span>.initialize_service<tt>
</tt>  <span class="r">end</span><tt>
</tt><tt>
</tt>  <span class="r">def</span> <span class="fu">bbs_call</span>(param) <tt>
</tt>     <span class="iv">@bbs</span>.bbs_call(param)<tt>
</tt>  <span class="r">end</span><tt>
</tt><span class="r">end</span><tt>
</tt><tt>
</tt><span class="r">if</span> <span class="pc">__FILE__</span> == <span class="gv">$0</span><tt>
</tt>  <span class="co">DRb</span>.start_service <span class="s"><span class="dl">'</span><span class="k">druby://127.0.0.1:6666</span><span class="dl">'</span></span>, <span class="co">JRubyServer</span>.new<tt>
</tt>  <span class="co">DRb</span>.thread.join<tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>
Execute like <i>ruby server.rb</i>, and then you&#8217;ll have the server listening on port 6666 of localhost. Nice, we can now call our Java service from other Ruby code with this simple snippet:
</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span class="s"><span class="dl">'</span><span class="k">drb</span><span class="dl">'</span></span><tt>
</tt><span class="co">DRb</span>.start_service<tt>
</tt><tt>
</tt>java_bbs = <span class="co">DRbObject</span>.new(<span class="pc">nil</span>, <span class="s"><span class="dl">'</span><span class="k">druby://127.0.0.1:6666</span><span class="dl">'</span></span>)<tt>
</tt><tt>
</tt>puts  java_bbs.bbs_call(<span class="s"><span class="dl">&quot;</span><span class="k">Whack!</span><span class="dl">&quot;</span></span>) <span class="c">#=&gt; &quot;Whacked!&quot;</span></pre>
</td>
</tr>
</table>
<p>
Kewl! Except for one big caveat. As of JRuby 1.0.x Java objects cannot be marshalled correctly so passing them to your Ruby code will cause all sorts of interesting hangs and crashes when you access them concurrently (see <a href="http://jira.codehaus.org/browse/JRUBY-1235" target="_blank">JRUBY-1235</a>). Untill JRuby 1.1 is out you can synchronize all your calls to JRuby and making sure you convert any results to proper Ruby objects before using them elsewhere in your Ruby code.
</p>
<p>
This hack saved me loads of (Java hacking) time!</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "pub-6322765154114793";
/* 300x250, created 7/3/11 */
google_ad_slot = "6228709946";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://www.railsguru.com/articles/2007/11/29/jruby-saves-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

