<?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>Mundo Ruby &#187; how-to</title>
	<atom:link href="http://www.mundoruby.com.ar/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mundoruby.com.ar</link>
	<description>Ruby Artists, Hackers y otras yerbas ...</description>
	<lastBuildDate>Wed, 12 Aug 2009 23:02:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>rake sh en otro directorio</title>
		<link>http://www.mundoruby.com.ar/2009/07/17/rake-sh-en-otro-directorio/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/17/rake-sh-en-otro-directorio/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 13:31:39 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=151</guid>
		<description><![CDATA[Problema: Quiero ejecutar un comando desde otro directorio en rake (por ejemplo, ejecutar un makefile que está en un subdirectorio).
Solución: Agrego al rakefile la posibilidad de ejecutar comandos en otro directorio. Para eso, al principio de mi rakefile puse:

require 'fileutils'

def sh_in_dir( dirname, *args, &#38;block )
  old_path = pwd
  FileUtils.chdir( dirname )
  sh( [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight:bold;">Problema:</span> Quiero ejecutar un comando desde otro directorio en rake (por ejemplo, ejecutar un makefile que está en un subdirectorio).<br />
<span style="font-weight:bold;">Solución:</span> Agrego al rakefile la posibilidad de ejecutar comandos en otro directorio. Para eso, al principio de mi rakefile puse:</p>
<pre class="ruby"><span class="string">
<pre style="font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 610px; padding: 10px; border: thin dashed initial;"><span style="color: #000044;">require</span> <span style="color: #444477; font-weight: bold;">'</span><span style="color: #994444;">fileutils</span><span style="color: #444477; font-weight: bold;">'</span>

<span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">sh_in_dir</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">dirname</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #444477; font-weight: bold;">*</span><span style="color: #000044;">args</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #444477; font-weight: bold;">&amp;</span><span style="color: #000044;">block</span> <span style="color: #444477; font-weight: bold;">)</span>
  <span style="color: #000044;">old_path</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">pwd</span>
  <span style="color: #0077ff;">FileUtils</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">chdir</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">dirname</span> <span style="color: #444477; font-weight: bold;">)</span>
  <span style="color: #000044;">sh</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">*</span><span style="color: #000044;">args</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #444477; font-weight: bold;">&amp;</span><span style="color: #000044;">block</span> <span style="color: #444477; font-weight: bold;">)</span>
  <span style="color: #0077ff;">FileUtils</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">chdir</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">old_path</span> <span style="color: #444477; font-weight: bold;">)</span>
<span style="color: #aa0000; font-weight: bold;">end</span></pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, fantasy; line-height: 19px; white-space: normal; font-size: 13px;">Happy hacking,</span></p>
<p></span></pre>
<p>Aureliano.</p>
<div class="blogger-post-footer"><img src="https://blogger.googleusercontent.com/tracker/1437970354124720603-7633002584629589611?l=aurelianito.blogspot.com" alt="" width="1" height="1" /></div>
<p>(Via <a href="http://aurelianito.blogspot.com/">aurelianito</a>.) Original Link: <a href="http://aurelianito.blogspot.com/2009/07/rake-sh-en-otro-directorio.html">rake sh en otro directorio</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/17/rake-sh-en-otro-directorio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyInstaller: Getting Started with Rails and SQLite3</title>
		<link>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-sqlite3/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-sqlite3/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 14:10:12 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=127</guid>
		<description><![CDATA[
A few folks asked this over the past weeks, and since I released preview1 version of RubyInstaller, wouldn&#8217;t be awesome I write a guide for it?
So, here we go

First, Getting Ruby
Please download from here one of the preview1 installers for Ruby.
For this demonstration, I&#8217;m going to use Ruby 1.9.1-p129. Downloaded, executed and installed to it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>
<p>A few folks asked this over the past weeks, and since I <a href="http://blog.mmediasys.com/2009/06/28/rubyinstaller-preview1-released/">released preview1</a> version of RubyInstaller, wouldn&#8217;t be awesome I write a guide for it?</p>
<p>So, here we go</p>
<p><span id="more-233"></span></p>
<h3>First, Getting Ruby</h3>
<p>Please download <a href="http://rubyinstaller.org/downloads/">from here</a> one of the preview1 installers for Ruby.</p>
<p>For this demonstration, I&#8217;m going to use Ruby 1.9.1-p129. Downloaded, executed and installed to it&#8217;s default location <code>C:\Ruby19</code></p>
<p>Now, start a Command prompt with Ruby (under start menu, inside Ruby 1.9.1-p129).</p>
<p><img src="http://blog.mmediasys.com/wp-content/uploads/2009/07/prompt.png" alt="Command Prompt with Ruby" title="Command Prompt with Ruby" width="515" height="365" class="alignnone size-full wp-image-238" /></p>
<h3>Getting <span class="caps">SQL</span>ite3</h3>
<p>As you may know, Windows do not came out of the box with libraries like <span class="caps">SQL</span>ite3. For this, we are going to download it from Internet.</p>
<p>Going to <a href="http://sqlite.org/download.html"><span class="caps">SQL</span>ite downloads</a>, under <em>Precompiled binaries for Windows</em>, download <code>sqlitedll-3_6_16.zip</code> and <code>sqlite-3_6_16.zip</code>. Those two packages contains the <span class="caps">DLL </span>(sqlite3.dll) and the command line executable for <span class="caps">SQL</span>ite (sqlite3.exe).</p>
<p>Please extract those contents inside <code>C:\Ruby19\bin</code></p>
<p>Now, let&#8217;s get the Ruby bindings for <span class="caps">SQL</span>ite3</p>
<h3>Getting <span class="caps">SQL</span>ite3/Ruby bindings</h3>
<p>As you may know, the preferred way to distribute Ruby libraries is using Gems. Users on other platforms usually compile themselves these components, using the mechanisms provided by the operating system distribution.</p>
<p>We are going to avoid the compilation process using pre-compiled binaries that has been <em>cooked</em> for us.</p>
<p>So, back to the Command Prompt with Ruby, let&#8217;s install the sqlite3 bindings:</p>
<pre>gem install sqlite3-ruby --source http://gems.rubyinstaller.org</pre>
<p>Adding <code>--source</code> help us indicate a non-standard location from where gems are going to be installed. RubyInstaller team has built and packaged special versions of these gems that we hope get published soon into RubyForge, the official place for gem distribution.</p>
<p>Once installed, you should see something like this at the screen:</p>
<pre>Successfully installed sqlite3-ruby-1.2.4.1-x86-mingw32
1 gem installed</pre>
<p>These special version of the gem are <em>fat binaries</em>, which means these can be safely installed on Ruby 1.8.6 or 1.9.1.</p>
<h3>Getting Rails</h3>
<p>Now it&#8217;s time to install and build a Rails application. First, let&#8217;s install the rails gem:</p>
<pre>gem install rails</pre>
<p>That command is going to take a bit, since is a 2MB or so download, and will install several of the Rails dependencies (ActiveRecord, ActionPack, ActiveSupport, etc). You should expect similar output to this:</p>
<pre>Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
6 gems installed</pre>
<p>Let&#8217;s build our application now.</p>
<h3>Creating a Rails application.</h3>
<p>Let&#8217;s call the application <code>railsapp</code></p>
<pre>rails railsapp</pre>
<p>An excerpt of the output you should get:</p>
<pre>      create
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  config/initializers
      create  config/locales
      create  db
...</pre>
<p>Rails 2.3.2 defaults it&#8217;s database format to <span class="caps">SQL</span>ite3, so there is no need for us to tweak anything.</p>
<p>Checking if everything is ok, using <code>script\about</code>:</p>
<pre>cd railsapp
ruby script\about</pre>
<p>And the output should be something like this:</p>
<pre>About your application's environment
Ruby version              1.9.1 (i386-mingw32)
RubyGems version          1.3.4
Rack version              1.0 bundled
Rails version             2.3.2
Active Record version     2.3.2
Action Pack version       2.3.2
Active Resource version   2.3.2
Action Mailer version     2.3.2
Active Support version    2.3.2
Application root          C:/Users/Luis/railsapp
Environment               development
Database adapter          sqlite3
Database schema version   0</pre>
<p>Now, it&#8217;s up to you create your models, controllers and everything.</p>
<h3>Some notes and considerations.</h3>
<p>At the time of this writing, Mongrel has not been updated to build and install properly either on 1.9 or MinGW versions of Ruby.</p>
<p>As part of Mongrel development team, I&#8217;m going to work on a solution for this in the upcoming days.</p>
<p>If you find something wrong with the Ruby Installer, please report <a href="http://rubyforge.org/tracker/?atid=715&amp;group_id=167&amp;func=browse">here</a>, but issues with your code, Rails or other are not responsability of RubyInstaller.</p>
<p>The binary gems provided at <code>gems.rubyinstaller.org</code> are based on our forks of sqlite3-ruby, which can be cloned and explored <a href="http://github.com/luislavena/sqlite3-ruby">here</a> at GitHub.</p>
<p>Keep in mind that some gems would not work under Ruby 1.9, or you will need a compiler (DevKit) for it. See previous post with details how to get those from our download page.</p>
</p>
<p>(Via <a href="http://blog.mmediasys.com">DEV_MEM.dump_to(:blog) &#8211; Multimedia systems blog</a>.) Original Link: <a href="http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-sqlite3/#comments">RubyInstaller: Getting Started with Rails and SQLite3</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-sqlite3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RubyInstaller: Getting Started with Rails and MySQL</title>
		<link>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-mysql/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-mysql/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 14:09:53 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[msyql]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=125</guid>
		<description><![CDATA[
This is a follow up instruction set from previous post, but this time, using MySQL

Getting Ruby
These steps are the same for Ruby 1.9 or Ruby 1.8, please feel free to download the installer from here
For this guide I&#8217;m going to use Ruby 1.9.1-p129, since it the coolest new version that all the guys are playing [...]]]></description>
			<content:encoded><![CDATA[<p>
<p>This is a follow up instruction set from <a href="http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-sqlite3/">previous post</a>, but this time, using MySQL</p>
<p><span id="more-250"></span></p>
<h3>Getting Ruby</h3>
<p>These steps are the same for Ruby 1.9 or Ruby 1.8, please feel free to download the installer <a href="http://rubyinstaller.org/downloads">from here</a></p>
<p>For this guide I&#8217;m going to use Ruby 1.9.1-p129, since it the coolest new version that all the guys are playing with <img src='http://blog.mmediasys.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Now, start a Command prompt with Ruby (under start menu, inside Ruby 1.9.1-p129).</p>
<p><img src="http://blog.mmediasys.com/wp-content/uploads/2009/07/prompt.png" alt="Command Prompt with Ruby 1.9" title="Command Prompt with Ruby 1.9" width="515" height="365" class="alignnone size-full wp-image-238" /></p>
<h3>Getting the right MySQL version</h3>
<p>While building the MySQL/Ruby bindings, we found that mixing versions of the bindings with different versions of MySQL installations ended on undesired results (abnormal program termination, weird errors, etc.)</p>
<p>For this guide, and because we are going to use binary gems, we are going to stick to MySQL version <strong>5.0.83</strong>. </p>
<p>Now is time to download MySQL. For this guide, I&#8217;m going to install the <em>essentials</em> version, which contains only MySQL and command line tools, no Query Builder or any other administrative tool.</p>
<p>Please go to <a href="http://dev.mysql.com/downloads/mysql/5.0.html#win32">this page</a> and download <em>Windows Essentials (x86)</em>. Once downloaded you will end with <code>mysql-essential-5.0.83-win32.msi</code> file. Execute it and install with defaults.</p>
<h3>Configure MySQL</h3>
<p>If you&#8217;re an advanced and savvy MySQL user, you can skip the following steps. For the sake of this guide, I&#8217;m going to list the simple options you must follow when installing it.</p>
<p>Once you installed MySQL, the installer should have started the <em>Configuration Wizard</em> page.</p>
<p>Inside of it, please apply the following options:</p>
<table>
<tr>
<th>Option/Screen</th>
<th>Value</th>
</tr>
<tr>
<td>Configuration Type</td>
<td>Detailed configuration</td>
</tr>
<tr>
<td>Server type</td>
<td>Developer Machine</td>
</tr>
<tr>
<td>Database usage</td>
<td>Transactional Database only</td>
</tr>
<tr>
<td>InnoDB datafile</td>
<td><em>Your option or leave defaults</em></td>
</tr>
<tr>
<td>Number of connections</td>
<td>Decision Support</td>
</tr>
<tr>
<td>Networking options</td>
<td>Check <em>Add firewall exceptions</em></td>
</tr>
<tr>
<td>Character set</td>
<td>Best support for Multilingualism (UTF8)</td>
</tr>
<tr>
<td>Windows Options</td>
<td>Add to <span class="caps">PATH </span>if you want <em>mysql</em> available on every prompt</td>
</tr>
<tr>
<td>Security Options</td>
<td>Uncheck if you want <em>root</em> password be blank</td>
</tr>
</table>
<p>Once done with all this, on the summary screen, please click <em>Execute</em> to complete the configuration of MySQL Server.</p>
<p>Under some system, starting of MySQL server will fail during this wizard, but don&#8217;t be afraid, most of the times, this can be safely ignored.</p>
<p>To check everything was properly installed, please go to the Start Menu, and inside <em>MySQL Server 5.0</em>, click on <em>MySQL Command Line Client</em></p>
<p>If you changed the <em>root</em> password, or, like me, leaved it unchecked, you can simply press enter when asked for the password and see that the server is running!</p>
<p><img src="http://blog.mmediasys.com/wp-content/uploads/2009/07/mysql-client.png" alt="MySQL Console Client" title="MySQL Console Client" width="566" height="353" class="alignnone size-full wp-image-253" /></p>
<p>If you decided to add MySQL to the <span class="caps">PATH, </span>you will require to restart your computer so the <span class="caps">PATH </span>change is available to the system.</p>
<p>If you decided not to add MySQL to the <span class="caps">PATH, </span>please go, with Explorer to the location where you installed MySQL Server and copy <code>libmySQL.dll</code> into <code>C:\Ruby19\bin</code></p>
<p>In my case, I found this file in <code>C:\Program Files\MySQL\MySQL Server 5.0\bin</code></p>
<p>Now, it is time to install the bindings.</p>
<h3>Getting MySQL/Ruby</h3>
<p>For this version of Ruby, there is no official binary gems for both Ruby 1.8 and 1.9. So we are going to install the specially built version from RubyInstaller gems repository. </p>
<p>At the <em>Command Prompt with Ruby</em>, please enter the following command:</p>
<pre>
gem install mysql --source http://gems.rubyinstaller.org
  </pre>
<p>This is going to install the special version of MySQL bindings. This version works with Ruby 1.8 and 1.9, since bundles <em>fat binaries</em>. You should expect a similar output like this:</p>
<pre>Successfully installed mysql-2.8.1.1-x86-mingw32
1 gem installed</pre>
<h3>Getting Rails</h3>
<p>Now is time to install Rails and build our application. At the same command prompt, please enter the following command:</p>
<pre>gem install rails</pre>
<p>This is going to take a bit, since Rails and it&#8217;s dependencies takes around 2MB or so, and need to be downloaded and installed.</p>
<p>Once done, expect see at the screen something like this:</p>
<pre>Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
6 gems installed</pre>
<h3>Creating a Rails application</h3>
<p>Let&#8217;s name our application <code>mysqlapp</code></p>
<pre>rails mysqlapp --database=mysql</pre>
<p>The <code>--database</code> option indicates to Rails that we want to use MySQL instead of the default database adapter (SQLite3).</p>
<p>Rails will output a lot of lines when creating your application structure, just an excerpt of what to see:</p>
<pre>
...
      create  config/database.yml
      create  config/routes.rb
      create  config/locales/en.yml
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_rails_defaults.rb
      create  config/initializers/session_store.rb
      create  config/environment.rb
...
</pre>
<h3>Configuring our Database</h3>
<p>Now Rails have configured for us the name of the database we want to use, and you can verify it in <code>config\database.yml</code></p>
<p>Rails will try to connect to <code>mysqlapp_development</code>, but that database do not exist in our fresh new MySQL server.</p>
<p>So, let&#8217;s create it:</p>
<pre>cd mysqlapp
rake db:create</pre>
<p>Just that, simple <code>db:create</code> is going to connect to our MySQL server, and create the database for us.</p>
<p>Keep in mind that if you changed root password or want to use other MySQL user to connect to the database, you need to edit <code>database.yml</code> to reflect those changes.</p>
<p>Let&#8217;s verify that everything is in place, using the following command:</p>
<pre>About your application's environment
Ruby version              1.9.1 (i386-mingw32)
RubyGems version          1.3.4
Rack version              1.0 bundled
Rails version             2.3.2
Active Record version     2.3.2
Action Pack version       2.3.2
Active Resource version   2.3.2
Action Mailer version     2.3.2
Active Support version    2.3.2
Application root          C:/Users/Luis/mysqlapp
Environment               development
Database adapter          mysql
Database schema version   0</pre>
<p>Now is up to you to create your models, controllers and views!</p>
<h3>Some notes and considerations</h3>
<p>On other post I&#8217;m going to guide you with steps on building the bindings against MySQL 5.1.36, since you will need to install the Ruby Development Kit and the development headers for MySQL.</p>
<p>If you find something wrong with the Ruby Installer, please report it <a href="http://rubyforge.org/tracker/?atid=715&amp;group_id=167&amp;func=browse">here</a>, but issues with your code, Rails or other are not responsability of RubyInstaller.</p>
<p>The binary gems provided at <code>gems.rubyinstaller.org</code> are based on our forks of mysql bindings, which can be cloned and explored <a href="http://github.com/luislavena/mysql-gem">here</a> at GitHub.</p>
<p>Keep in mind that some gems would not work under Ruby 1.9, or you will need a compiler (DevKit) for it. See previous post with details how to get those from our download page.</p>
</p>
<p>(Via <a href="http://blog.mmediasys.com">DEV_MEM.dump_to(:blog) &#8211; Multimedia systems blog</a>.) Original Link: <a href="http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-mysql/#comments">RubyInstaller: Getting Started with Rails and MySQL</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/07/rubyinstaller-getting-started-with-rails-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m back with some Code &#8230;</title>
		<link>http://www.mundoruby.com.ar/2009/07/06/im-back-with-some-code/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/06/im-back-with-some-code/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 17:52:30 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=123</guid>
		<description><![CDATA[
Well, hello again, long time since the last post. I went on vacations, work a lot and did some programming. Let&#8217;s talk abount the programming part, since it is the most interesting one.  
I created a small library called &#8220;Esearchy&#8221; capable of searching the internet for email addresses. Currently, we the supported search methods [...]]]></description>
			<content:encoded><![CDATA[<p>
<p>Well, hello again, long time since the last post. I went on vacations, work a lot and did some programming. Let&#8217;s talk abount the programming part, since it is the most interesting one. <img src='http://www.mundoruby.com.ar/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I created a small library called &#8220;Esearchy&#8221; capable of searching the internet for email addresses. Currently, we the supported search methods are  engines such as Google, Bing, Yahoo, PGP servers, GoogleGroups, etc , but I intend to add many more.<br />
Also, the library searches inside .pdf and .txt files for emails addresses and adds them to the list of found accounts.  </p>
<p>For now, there are two main ways of performing a search, &#8220;the ruby way&#8221;</p>
<div class="geshifilter">
<div class="geshifilter-ruby" style="font-family: monospace;">
<ol>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal"> Esearchy.<span style="color:#9900CC;">create</span> <span style="color:#996600;">&quot;domain.com&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |domain|</div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; &nbsp;domain.<span style="color:#9900CC;">maxhits</span> = <span style="color:#006666;">500</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; &nbsp;domain.<span style="color:#9900CC;">search</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; &nbsp;domain.<span style="color:#9900CC;">clean</span> <span style="color:#006600; font-weight:bold;">&#123;</span>|e| e =~ /&lt;|&gt;/ <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; &nbsp;domain.<span style="color:#9900CC;">save_to_file</span> <span style="color:#996600;">&quot;~/emails.txt&quot;</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp;<span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
</ol>
</div>
</div>
<p>and the more classic way in which users can create an Esearchy objetc and work on it</p>
<p>
<div class="geshifilter">
<div class="geshifilter-ruby" style="font-family: monospace;">
<ol>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal"> &nbsp;domain = Esearchy.<span style="color:#9900CC;">new</span> <span style="color:#ff3333; font-weight:bold;">:query</span> =&gt; <span style="color:#996600;">&quot;domain.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:maxhits</span> =&gt; <span style="color:#006666;">500</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; domain.<span style="color:#9900CC;">search</span></div>
</li>
<li style="font-family: monospace; font-weight: normal;">
<div style="font-family: monospace; font-weight: normal; font-style: normal">&nbsp; domain.<span style="color:#9900CC;">save_to_file</span> <span style="color:#996600;">&quot;~/emails.txt&quot;</span></div>
</li>
</ol>
</div>
</div>
<p>For now , that&#8217;s it for now , but keep on tuned for more shitty code ajjajaa</p>
</p>
<p>(Via <a href="http://www.freedomcoder.com.ar">自由編碼人</a>.) Original Link: <a href="http://www.freedomcoder.com.ar/node/153#comments">I&#8217;m back with some Code &#8230;</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/06/im-back-with-some-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patch en Regexp para poder usarlas como clave en un Hash</title>
		<link>http://www.mundoruby.com.ar/2009/07/06/patch-en-regexp-para-poder-usarlas-como-clave-en-un-hash/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/06/patch-en-regexp-para-poder-usarlas-como-clave-en-un-hash/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 17:51:56 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=121</guid>
		<description><![CDATA[Siguiendo mi proyecto de hacer mi wiki en Ruby, encontré un comportamiento muy raro.
Generé un hash (que se llama @rules) que no tiene un elemento que tiene. O sea, @rules[@rules.keys[2]] da nil, pero @rules.values[2] devuelve el objeto asociado a la clave @rules.keys[2]. Como este hash tiene como claves un montón de expresiones regulares, me imaginé [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo mi proyecto de hacer mi wiki en Ruby, encontré un comportamiento muy raro.<br />
Generé un hash (que se llama @rules) que no tiene un elemento que tiene. O sea, <code>@rules[@rules.keys[2]]</code> da nil, pero <code>@rules.values[2]</code> devuelve el objeto asociado a la clave <code>@rules.keys[2]</code>. Como este hash tiene como claves un montón de expresiones regulares, me imaginé que había un problema con el hash y el eql? de Regexp, así que los implementé de nuevo y monkeypatchié.<br />
Este es el código:</p>
<pre class="ruby">
<pre style="font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 608px; padding: 10px; border: thin dashed initial;"><span style="color: #aa0000; font-weight: bold;">class </span><span style="color: #007744;">Regexp</span>
 <span style="color: #000044;">alias_method</span> <span style="color: #009999;"> <img src='http://www.mundoruby.com.ar/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ld_rapidito_inspect</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #009999;">:inspect</span>

 <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">inspect</span>
   <span style="color: #337777;">@inspect</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">old_rapidito_inspect</span> <span style="color: #aa0000; font-weight: bold;">if</span> <span style="color: #337777;">@inspect</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">nil?</span>
   <span style="color: #337777;">@inspect</span>
 <span style="color: #aa0000; font-weight: bold;">end</span>

 <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">eql?</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">other</span> <span style="color: #444477; font-weight: bold;">)</span>
   <span style="color: #0077ff;">false</span> <span style="color: #aa0000; font-weight: bold;">if</span> <span style="color: #000044;">other</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #aa0000; font-weight: bold;">class </span><span style="color: #007744;">!=</span> <span style="color: #000044;">Regexp</span>
   <span style="color: #000044;">self</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">inspect</span> <span style="color: #444477; font-weight: bold;">==</span> <span style="color: #000044;">other</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">inspect</span>
 <span style="color: #aa0000; font-weight: bold;">end</span>

 <span style="color: #000044;">alias_method</span> <span style="color: #009999;">:"</span><span style="color: #009999;">==</span><span style="color: #009999;">"</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #009999;">:eql?</span>

 <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">hash</span>
   <span style="color: #0077ff;">self</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">inspect</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">hash</span>
 <span style="color: #aa0000; font-weight: bold;">end</span>
<span style="color: #aa0000; font-weight: bold;">end</span></pre>
</pre>
<p>Esta corrección me anduvo con la siguiente versión de ruby:</p>
<pre>
<pre style="font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 608px; padding: 10px; border: thin dashed initial;">$ ruby --version
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]</pre>
</pre>
<p>Espero que les sirva.<br />
Happy hacking,<br />
Aureliano.</p>
<div class="blogger-post-footer"><img src="https://blogger.googleusercontent.com/tracker/1437970354124720603-1030567752923382780?l=aurelianito.blogspot.com" alt="" width="1" height="1" /></div>
<p>(Via <a href="http://aurelianito.blogspot.com/">aurelianito</a>.) Original Link: <a href="http://aurelianito.blogspot.com/2009/07/patch-en-regexp-para-poder-usarlas-como.html">Patch en Regexp para poder usarlas como clave en un Hash</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/06/patch-en-regexp-para-poder-usarlas-como-clave-en-un-hash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Más rapidito</title>
		<link>http://www.mundoruby.com.ar/2009/07/01/mas-rapidito/</link>
		<comments>http://www.mundoruby.com.ar/2009/07/01/mas-rapidito/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:22:18 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=119</guid>
		<description><![CDATA[Como les estuve contando, sigo escribiendo mi wiki. Ya parsea un subconjunto interesante del lenguaje definido por trac.
Siguiendo la tradición, les cuento como está avanzando el tokenizer. Al tokenizer lo simplifiqué para que devuelva la expresión regular que matcheo junto con el match (en vez del &#8220;tipo&#8221;). Esto hizo que la interfase para definir las [...]]]></description>
			<content:encoded><![CDATA[<p>Como <a href="http://aurelianito.blogspot.com/2009/06/tokenizer-de-rapidito.html">les</a> <a href="http://aurelianito.blogspot.com/2009/06/tokenizer-de-rapidito-segunda-version.html">estuve</a> <a href="http://aurelianito.blogspot.com/2009/06/pequenas-delicias-de-las-expresiones.html">contando</a>, sigo escribiendo mi wiki. Ya parsea un subconjunto interesante del lenguaje definido por <a href="http://trac.edgewall.org">trac</a>.<br />
Siguiendo la tradición, les cuento como está avanzando el tokenizer. Al tokenizer lo simplifiqué para que devuelva la expresión regular que matcheo junto con el match (en vez del &#8220;tipo&#8221;). Esto hizo que la interfase para definir las reglas para tokenizar sea más simple. Si no hay ninguna regla que matchee sigue devolviendo <tt>["string", :text]</tt>.<br />
Sin más, acá el código:</p>
<pre class="ruby">
<pre style="font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 608px; padding: 10px; border: thin dashed initial;"><span style="color: #aa0000; font-weight: bold;">module </span><span style="color: #005500;">Rapidito</span>
  <span style="color: #aa0000; font-weight: bold;">class </span><span style="color: #007744;">Tokenizer</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">initialize</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">*</span><span style="color: #000044;">delimiters</span> <span style="color: #444477; font-weight: bold;">)</span>
      <span style="color: #337777;">@delimiter_list</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">delimiters</span> <span style="color: #444477; font-weight: bold;">+</span>  <span style="color: #444477; font-weight: bold;">[/</span><span style="color: #bb6666;"><span>\z</span></span><span style="color: #444477; font-weight: bold;">/]</span>
      <span style="color: #337777;">@match_cache</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">nil</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">source</span>
      <span style="color: #000044;">valid_cache?</span> <span style="color: #444477; font-weight: bold;">?</span> <span style="color: #337777;">@match_cache</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span> <span style="color: #444477; font-weight: bold;">+</span> <span style="color: #337777;">@source</span> <span style="color: #444477; font-weight: bold;">:</span> <span style="color: #337777;">@source</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">source=</span><span style="color: #444477; font-weight: bold;">(</span><span style="color: #000044;">s</span><span style="color: #444477; font-weight: bold;">)</span>
      <span style="color: #337777;">@match_cache</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">nil</span>
      <span style="color: #337777;">@source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">s</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">has_next?</span>
      <span style="color: #444477; font-weight: bold;">!</span><span style="color: #337777;">@source</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">empty?</span> <span style="color: #444477; font-weight: bold;">||</span> <span style="color: #000044;">valid_cache?</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">valid_cache?</span>
      <span style="color: #444477; font-weight: bold;">(!</span><span style="color: #337777;">@match_cache</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">nil?</span><span style="color: #444477; font-weight: bold;">)</span> <span style="color: #444477; font-weight: bold;">&amp;&amp;</span> <span style="color: #444477; font-weight: bold;">(</span><span style="color: #337777;">@match_cache</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span> <span style="color: #444477; font-weight: bold;">&gt;</span> <span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">next_match</span>
      <span style="color: #337777;">@delimiter_list</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">map</span> <span style="color: #444477; font-weight: bold;">{|</span><span style="color: #000044;">regex</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #444477; font-weight: bold;">[</span><span style="color: #000044;">regex</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">match</span><span style="color: #444477; font-weight: bold;">(</span><span style="color: #337777;">@source</span><span style="color: #444477; font-weight: bold;">),</span><span style="color: #000044;">regex</span><span style="color: #444477; font-weight: bold;">]}.</span><span style="color: #000044;">reject</span> <span style="color: #444477; font-weight: bold;">{|</span><span style="color: #000044;">p</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #000044;">p</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">nil?</span><span style="color: #444477; font-weight: bold;">}.</span><span style="color: #000044;">inject</span> <span style="color: #aa0000; font-weight: bold;">do</span>
        <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">better</span><span style="color: #444477; font-weight: bold;">,</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">|</span>
        <span style="color: #000044;">better_pos</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">better</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">pre_match</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span>
        <span style="color: #000044;">new_pos</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">pre_match</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span>

        <span style="color: #aa0000; font-weight: bold;">if</span> <span style="color: #000044;">better_pos</span> <span style="color: #444477; font-weight: bold;">&lt;</span> <span style="color: #000044;">new_pos</span>
          <span style="color: #000044;">better</span>
        <span style="color: #aa0000; font-weight: bold;">elsif</span> <span style="color: #000044;">new_pos</span> <span style="color: #444477; font-weight: bold;">&lt;</span> <span style="color: #000044;">better_pos</span>
          <span style="color: #000044;">new</span>
        <span style="color: #aa0000; font-weight: bold;">elsif</span> <span style="color: #000044;">better</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span> <span style="color: #444477; font-weight: bold;">&gt;</span> <span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span>
          <span style="color: #000044;">better</span>
        <span style="color: #aa0000; font-weight: bold;">else</span>
          <span style="color: #000044;">new</span>
        <span style="color: #aa0000; font-weight: bold;">end</span>
      <span style="color: #aa0000; font-weight: bold;">end</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">next_token</span>
      <span style="color: #aa0000; font-weight: bold;">if</span> <span style="color: #337777;">@match_cache</span> <span style="color: #000055; font-style: italic;">#cached delimiter</span>
        <span style="color: #000044;">rv</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #337777;">@match_cache</span>
        <span style="color: #337777;">@match_cache</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">nil</span>
        <span style="color: #aa0000; font-weight: bold;">return</span> <span style="color: #000044;">rv</span>
      <span style="color: #aa0000; font-weight: bold;">end</span>

      <span style="color: #000044;">match</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">next_match</span>
      <span style="color: #000044;">p</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">match</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">pre_match</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span>
      <span style="color: #337777;">@source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #337777;">@source</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #000044;">p</span> <span style="color: #444477; font-weight: bold;">+</span> <span style="color: #000044;">match</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #337777;">@source</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">length</span><span style="color: #444477; font-weight: bold;">]</span>

      <span style="color: #aa0000; font-weight: bold;">if</span> <span style="color: #000044;">p</span> <span style="color: #444477; font-weight: bold;">==</span> <span style="color: #dd5555;">0</span> <span style="color: #000055; font-style: italic;">#delimiter</span>
        <span style="color: #000044;">match</span>
      <span style="color: #aa0000; font-weight: bold;">else</span> <span style="color: #000055; font-style: italic;">#text</span>
        <span style="color: #337777;">@match_cache</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #000044;">match</span>
        <span style="color: #444477; font-weight: bold;">[</span><span style="color: #000044;">match</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">pre_match</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">]</span>
      <span style="color: #aa0000; font-weight: bold;">end</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>

    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">all_tokens</span>
      <span style="color: #000044;">tokens</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">[]</span>
      <span style="color: #aa0000; font-weight: bold;">while</span> <span style="color: #000044;">has_next?</span>
        <span style="color: #000044;">tokens</span> <span style="color: #444477; font-weight: bold;">&lt;&lt;</span> <span style="color: #000044;">next_token</span>
      <span style="color: #aa0000; font-weight: bold;">end</span>
      <span style="color: #000044;">tokens</span>
    <span style="color: #aa0000; font-weight: bold;">end</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>
<span style="color: #aa0000; font-weight: bold;">end</span></pre>
</pre>
<p>Y si miran los tests de unidad, van a ver que también quedaron más lindos:</p>
<pre class="ruby">
<pre style="font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 608px; padding: 10px; border: thin dashed initial;"><span style="color: #000044;">require</span> <span style="color: #444477; font-weight: bold;">'</span><span style="color: #994444;">test/unit</span><span style="color: #444477; font-weight: bold;">'</span>
<span style="color: #000044;">require</span> <span style="color: #444477; font-weight: bold;">'</span><span style="color: #994444;">rapidito/tokenizer</span><span style="color: #444477; font-weight: bold;">'</span>

<span style="color: #000044;">include</span> <span style="color: #0077ff;">Rapidito</span>

<span style="color: #aa0000; font-weight: bold;">class </span><span style="color: #007744;">TokenizerTest</span> <span style="color: #444477; font-weight: bold;">&lt;</span> <span style="color: #0077ff;">Test</span><span style="color: #444477; font-weight: bold;">::</span><span style="color: #0077ff;">Unit</span><span style="color: #444477; font-weight: bold;">::</span><span style="color: #0077ff;">TestCase</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_no_token</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">aaaa</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">aaaa</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">false</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">assert_all_tokens</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">expected</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tokenizer</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #000044;">expected</span><span style="color: #444477; font-weight: bold;">,</span>
      <span style="color: #000044;">tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">all_tokens</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">map</span> <span style="color: #444477; font-weight: bold;">{</span> <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">token</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">kind</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #444477; font-weight: bold;">[</span><span style="color: #000044;">token</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">to_s</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">kind</span><span style="color: #444477; font-weight: bold;">]</span> <span style="color: #444477; font-weight: bold;">}</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_two_delimiters</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span>
      <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;"><span>\|</span></span><span style="color: #444477; font-weight: bold;">/,</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">;;</span><span style="color: #444477; font-weight: bold;">/</span>
    <span style="color: #444477; font-weight: bold;">)</span>

    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">aa|bbb;;;;cccc</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">assert_all_tokens</span> \
      <span style="color: #444477; font-weight: bold;">[</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">aa</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">|</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;"><span>\|</span></span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">bbb</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span>
        <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">;;</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">;;</span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">;;</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">;;</span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">cccc</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">]</span> <span style="color: #444477; font-weight: bold;">],</span>
      <span style="color: #000044;">tok</span>

    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">aa;;bbb||cccc</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">assert_all_tokens</span> \
      <span style="color: #444477; font-weight: bold;">[</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">aa</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">;;</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">;;</span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">bbb</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span>
        <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">|</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;"><span>\|</span></span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">|</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;"><span>\|</span></span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">cccc</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">]</span> <span style="color: #444477; font-weight: bold;">],</span>
      <span style="color: #000044;">tok</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_choose_longest_match</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span>
      <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">aa</span><span style="color: #444477; font-weight: bold;">/,</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">aaa</span><span style="color: #444477; font-weight: bold;">/</span>
    <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">aaaa</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">assert_all_tokens</span> <span style="color: #444477; font-weight: bold;">[</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">aaa</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">aaa</span><span style="color: #444477; font-weight: bold;">/],</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">a</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span> <span style="color: #444477; font-weight: bold;">]</span> <span style="color: #444477; font-weight: bold;">],</span> <span style="color: #000044;">tok</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_reset_precache</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span>
      <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;"><span>\|</span></span><span style="color: #444477; font-weight: bold;">/,</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">,</span><span style="color: #444477; font-weight: bold;">/</span>
    <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">original start|original end</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">new start,new end</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #444477; font-weight: bold;">["</span><span style="color: #994444;">new start</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #009999;">:text</span><span style="color: #444477; font-weight: bold;">],</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_almost_finished</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">!</span><span style="color: #444477; font-weight: bold;">/</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">bang!</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">false</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_carriage_return_ending</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">!</span><span style="color: #444477; font-weight: bold;">/</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">bang!<span>\n</span></span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;"><span>\n</span></span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">false</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_transparent_caching</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">!</span><span style="color: #444477; font-weight: bold;">/</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">bang!pum</span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>

    <span style="color: #000044;">assert_equal</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">!pum</span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span>
  <span style="color: #aa0000; font-weight: bold;">end</span>

  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_match_klass</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #444477; font-weight: bold;">/</span><span style="color: #bb6666;">!</span><span style="color: #444477; font-weight: bold;">/</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">!bang!pum</span><span style="color: #444477; font-weight: bold;">"</span>

    <span style="color: #000044;">assert_equal</span> \
      <span style="color: #444477; font-weight: bold;">[</span><span style="color: #0077ff;">MatchData</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #0077ff;">String</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #0077ff;">MatchData</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #0077ff;">String</span><span style="color: #444477; font-weight: bold;">],</span>
      <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">all_tokens</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">map</span> <span style="color: #444477; font-weight: bold;">{</span> <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">kind</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #aa0000; font-weight: bold;">class </span><span style="color: #007744;">}</span>
  <span style="color: #000044;">end</span>
<span style="color: #aa0000; font-weight: bold;">end</span></pre>
</pre>
<p>Happy hacking,<br />
Aureliano.</p>
<div class="blogger-post-footer"><img src="https://blogger.googleusercontent.com/tracker/1437970354124720603-1410164064116629157?l=aurelianito.blogspot.com" alt="" width="1" height="1" /></div>
<p>(Via <a href="http://aurelianito.blogspot.com/">aurelianito</a>.)  Original Link: <a href="http://aurelianito.blogspot.com/2009/06/mas-rapidito.html">Más rapidito</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/07/01/mas-rapidito/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pequeñas delicias de las expresiones regulares</title>
		<link>http://www.mundoruby.com.ar/2009/06/13/pequenas-delicias-de-las-expresiones-regulares/</link>
		<comments>http://www.mundoruby.com.ar/2009/06/13/pequenas-delicias-de-las-expresiones-regulares/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 19:57:28 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=113</guid>
		<description><![CDATA[Como les conté acá y acá, estoy escribiendo un tokenizador para un wiki que estoy programando. Y hoy me encontré con una cosa muy extraña de las expresiones regulares.
En ruby la función match sirve para buscar el primer match de una regex dentro de un string. Por ejemplo (usando el irb):

irb(main):001:0&#62; m = /a/.match "babab"
=&#62; #&#60;MatchData "a"&#62;
irb(main):002:0&#62; m.pre_match
=&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Como les conté <a href="http://aurelianito.blogspot.com/2009/06/tokenizer-de-rapidito.html">acá</a> y <a href="http://aurelianito.blogspot.com/2009/06/tokenizer-de-rapidito-segunda-version.html">acá</a>, estoy escribiendo un tokenizador para un wiki que estoy programando. Y hoy me encontré con una cosa muy extraña de las expresiones regulares.<br />
En ruby la función <code>match</code> sirve para buscar el primer match de una regex dentro de un string. Por ejemplo (usando el irb):</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">irb(main):001:0&gt; m = /a/.match "babab"
=&gt; #&lt;MatchData "a"&gt;
irb(main):002:0&gt; m.pre_match
=&gt; "b"
irb(main):003:0&gt; m[0]
=&gt; "a"</pre>
</pre>
<p>En particular, el <code>pre_match</code> es lo que está antes del match en el string. También según había entendido (mal) <code>/\Z/</code> matchea con el final del string. Por ejemplo:</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">irb(main):004:0&gt; m = /\Z/.match "hola"
=&gt; #&lt;MatchData ""&gt;
irb(main):005:0&gt; m.pre_match
=&gt; "hola"</pre>
</pre>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Pero, <code>/\Z/</code> tiene un comportamiento muy extraño, aunque <a href="http://www.regular-expressions.info/reference.html">documentado</a>, cuando el último caracter antes del final es un <code>\n</code>. Lo que pasa es que el <code>pre_match</code> queda ¡sin el<code>\n</code> del final!. Lo muestro en el irb:</span></pre>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">irb(main):006:0&gt; m = /\Z/.match "\n"
=&gt; #&lt;MatchData ""&gt;
irb(main):007:0&gt; m.pre_match
=&gt; ""</pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Para que no se manduque el <code>\n</code>, hay que usar <code>/\z/</code> (¡en minúscula!):</span></pre>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">irb(main):008:0&gt; m = /\z/.match "\n"
=&gt; #&lt;MatchData ""&gt;
irb(main):009:0&gt; m.pre_match
=&gt; "\n"</pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Por lo tanto tuve que tocar el tokenizer, ahora la función de initialize quedó así (miren el cambio de la "Z" a "z"):</span></pre>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">    <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">initialize</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #000044;">delimiters</span> <span style="color: #444477; font-weight: bold;">)</span>
      <span style="color: #337777;">@delimiter_list</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">[[/</span><span style="color: #bb6666;"><span>\z</span></span><span style="color: #444477; font-weight: bold;">/,</span> <span style="color: #009999;">:finish</span><span style="color: #444477; font-weight: bold;">]]</span> <span style="color: #444477; font-weight: bold;">+</span>
        <span style="color: #000044;">delimiters</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">to_a</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">map</span> <span style="color: #444477; font-weight: bold;">{</span> <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">k</span><span style="color: #444477; font-weight: bold;">,</span><span style="color: #000044;">arr</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #000044;">arr</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">map</span> <span style="color: #444477; font-weight: bold;">{</span> <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">re</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #444477; font-weight: bold;">[</span><span style="color: #000044;">re</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">k</span><span style="color: #444477; font-weight: bold;">]</span> <span style="color: #444477; font-weight: bold;">}</span> <span style="color: #444477; font-weight: bold;">}.</span><span style="color: #000044;">inject</span><span style="color: #444477; font-weight: bold;">([])</span> <span style="color: #444477; font-weight: bold;">{</span> <span style="color: #444477; font-weight: bold;">|</span><span style="color: #000044;">ac</span><span style="color: #444477; font-weight: bold;">,</span><span style="color: #000044;">ps</span><span style="color: #444477; font-weight: bold;">|</span> <span style="color: #000044;">ac</span> <span style="color: #444477; font-weight: bold;">+</span> <span style="color: #000044;">ps</span> <span style="color: #444477; font-weight: bold;">}</span>
      <span style="color: #337777;">@match_cache</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">nil</span>
    <span style="color: #aa0000; font-weight: bold;">end</span></pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Y el test que captura el problema que genera usar \Z en vez de \z quedó así:</span></pre>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;">
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 1.1em; background-color: #ffffcc; color: #000000; overflow-x: auto; overflow-y: auto; margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; width: 631px; padding: 10px;">  <span style="color: #aa0000; font-weight: bold;">def </span><span style="color: #007777;">test_carriage_return_ending</span>
    <span style="color: #000044;">tok</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #0077ff;">Tokenizer</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">new</span><span style="color: #444477; font-weight: bold;">(</span> <span style="color: #009999;">:a_kind</span> <span style="color: #444477; font-weight: bold;">=&gt;</span> <span style="color: #444477; font-weight: bold;">[/</span><span style="color: #bb6666;">!</span><span style="color: #444477; font-weight: bold;">/]</span> <span style="color: #444477; font-weight: bold;">)</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">source</span> <span style="color: #444477; font-weight: bold;">=</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;">bang!<span>\n</span></span><span style="color: #444477; font-weight: bold;">"</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">true</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #444477; font-weight: bold;">"</span><span style="color: #994444;"><span>\n</span></span><span style="color: #444477; font-weight: bold;">",</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">next_token</span><span style="color: #444477; font-weight: bold;">[</span><span style="color: #dd5555;">0</span><span style="color: #444477; font-weight: bold;">].</span><span style="color: #000044;">to_s</span>
    <span style="color: #000044;">assert_equal</span> <span style="color: #0077ff;">false</span><span style="color: #444477; font-weight: bold;">,</span> <span style="color: #000044;">tok</span><span style="color: #444477; font-weight: bold;">.</span><span style="color: #000044;">has_next?</span>
  <span style="color: #aa0000; font-weight: bold;">end</span></pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Happy hacking,</span></pre>
<p>Aureliano.</p>
<div><img style="border: 0px initial initial;" src="https://blogger.googleusercontent.com/tracker/1437970354124720603-4301954417416078176?l=aurelianito.blogspot.com" alt="" width="1" height="1" /></div>
<p>(Via <a href="http://aurelianito.blogspot.com/">aurelianito</a>.) Original Link: <a href="http://aurelianito.blogspot.com/2009/06/pequenas-delicias-de-las-expresiones.html">Pequeñas delicias de las expresiones regulares</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/06/13/pequenas-delicias-de-las-expresiones-regulares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyInstaller: One-Clicks need a new home, can you help him?</title>
		<link>http://www.mundoruby.com.ar/2009/05/19/rubyinstaller-one-clicks-need-a-new-home-can-you-help-him/</link>
		<comments>http://www.mundoruby.com.ar/2009/05/19/rubyinstaller-one-clicks-need-a-new-home-can-you-help-him/#comments</comments>
		<pubDate>Tue, 19 May 2009 13:59:13 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[one-click]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=90</guid>
		<description><![CDATA[&#8220;
I must say that my skills to ask for something are really lacking, and my design skills are even worse.
So, I’m bringing this topic to the table, seeking for ideas on how to improve the Ruby on Windows image beyond just code.
I’m willing to offer money to pay for it, since I’m quite aware that [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;
<p>I must say that my skills to ask for something are really lacking, and my design skills are even worse.</p>
<p>So, I’m bringing this topic to the table, seeking for ideas on how to improve the Ruby on Windows image beyond just code.</p>
<p>I’m willing to offer money to pay for it, since I’m quite aware that Open Source and contributions don’t put food on the table.</p>
<p>Of course, I’m not rich, so the balance needs to be found <img src='http://blog.mmediasys.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So, what is the idea:</p>
<ul>
<li>Build the website with Radiant or a simple CMS over Ruby</li>
<li>Design needs to be simple and provide access to:</li>
<ol>
<li>News feed (small articles)</li>
<li>Download info and links</li>
<li>Getting Started Resources (info and links)</li>
<li>Contribute (RubyForge and GitHub info)</li>
<li>Support (access to mailing list and forums of interest)</li>
</ol>
<li>Initial artwork (logo and iso) already exist</li>
<li>Application icons can be highly improved <img src='http://blog.mmediasys.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </li>
</ul>
<p>For the record: there is no need to be a Windows user or designer, so people on Linux and OSX are welcome <img src='http://blog.mmediasys.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>If there is more interest, maybe a Bounty can be opened, but time, feedback and <em>community</em> response will tell.</p>
<p>Please, comment and pass the message!</p>
<p>&#8220;</p>
<p>(Via <a href="http://blog.mmediasys.com">DEV_MEM.dump_to(:blog) &#8211; Multimedia systems blog</a>.) Original Link: <a href="http://blog.mmediasys.com/2009/05/19/rubyinstaller-one-clicks-need-a-new-home-can-you-help-him/#comments">RubyInstaller: One-Clicks need a new home, can you help him?</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/05/19/rubyinstaller-one-clicks-need-a-new-home-can-you-help-him/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pure-Ruby Readline: Released 0.1.2</title>
		<link>http://www.mundoruby.com.ar/2009/05/19/pure-ruby-readline-released-012/</link>
		<comments>http://www.mundoruby.com.ar/2009/05/19/pure-ruby-readline-released-012/#comments</comments>
		<pubDate>Tue, 19 May 2009 13:59:06 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[readline]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=88</guid>
		<description><![CDATA[&#8220;
Well, well, less than 24 hours since my last blog post, I have more updates for you!

Thanks to GitHub, rb-readline, the Pure-Ruby Readline project I’ve mentioned earlier, have now two forks and 3 bugs fixed!
Thanks to Roger Pack and Jugyo !!!
Now, there is no gem for rb-readline, mainly because readline needs to be available even [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;
<p>Well, well, less than 24 hours since my last <a href="http://blog.mmediasys.com/2009/05/17/rubyinstaller-updated-packages-and-other-news/">blog post</a>, I have more updates for you!</p>
<p><span id="more-175"></span></p>
<p>Thanks to <a href="http://github.com">GitHub</a>, rb-readline, the Pure-Ruby Readline project I’ve mentioned earlier, have now <a href="http://github.com/luislavena/rb-readline/network">two forks</a> and 3 bugs fixed!</p>
<p>Thanks to <a href="http://github.com/rogerdpack/">Roger Pack</a> and <a href="http://github.com/jugyo/">Jugyo</a> !!!</p>
<p>Now, there is no gem for rb-readline, mainly because <code>readline</code> needs to be available even if RubyGems is not loaded (like on IRB).</p>
<p>So, to install the updated package:</p>
<ul>
<li>Download <a href="http://cloud.github.com/downloads/luislavena/rb-readline/rb-readline-0.1.2.zip">rb-readline-0.1.2.zip</a></li>
<li>Extract to a folder and open a command prompt there</li>
<li>Execute <code>ruby setup.rb</code></li>
</ul>
<p>That should update the installed RbReadline, but just to verify:</p>
<pre><code>ruby -rreadline -e 'puts Readline::RB_READLINE_VERSION'</code></pre>
<p>The output should say <strong>0.1.2</strong></p>
<p>That’s all! Enjoy!</p>
<p>&#8220;</p>
<p>(Via <a href="http://blog.mmediasys.com">DEV_MEM.dump_to(:blog) &#8211; Multimedia systems blog</a>.) Original Link: <a href="http://blog.mmediasys.com/2009/05/19/pure-ruby-readline-released-012/#comments">Pure-Ruby Readline: Released 0.1.2</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/05/19/pure-ruby-readline-released-012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Instalando Mod_Ruby</title>
		<link>http://www.mundoruby.com.ar/2009/04/22/instalando-mod_ruby/</link>
		<comments>http://www.mundoruby.com.ar/2009/04/22/instalando-mod_ruby/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 13:21:55 +0000</pubDate>
		<dc:creator>FreedomCoder</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mod_ruby]]></category>

		<guid isPermaLink="false">http://www.mundoruby.com.ar/?p=78</guid>
		<description><![CDATA[&#8220;

Bueno dada la escasa y fea documentación que mod_ruby tiene me decidí a escribir un pequeño tutorial de instalación del mismo en debian, que paso a detallar:
Primero instalamos el modulo de apache para ruby (mod_ruby)
apt-get install libapache2-mod-ruby
Luego debemos crear el siguiente archivo:
vi /etc/apache2/mods-available/ruby.conf
y ponemos lo siguiente:
&#60;IfModule mod_ruby.c&#62;
  RubyRequire apache/ruby-run

  &#60;Files *.rbx&#62;
  SetHandler [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;
<div class='snap_preview'>
<p>Bueno dada la escasa y fea documentación que mod_ruby tiene me decidí a escribir un pequeño tutorial de instalación del mismo en debian, que paso a detallar:</p>
<p>Primero instalamos el modulo de apache para ruby (mod_ruby)</p>
<pre>apt-get install libapache2-mod-ruby</pre>
<p>Luego debemos crear el siguiente archivo:<br />
vi /etc/apache2/mods-available/ruby.conf</p>
<p>y ponemos lo siguiente:</p>
<pre>&lt;IfModule mod_ruby.c&gt;
  RubyRequire apache/ruby-run

  &lt;Files *.rbx&gt;
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  &lt;/Files&gt;
&lt;/IfModule&gt;</pre>
<p>Entre otras cosas le decimos que debe tratar los archivos .rbx como<br />
archivos de ruby.</p>
<p>Luego de esto ya tenemos los dos archivos necesarios para habilitar el módulo en apache:</p>
<p>ruby.load (que secopia al instalar el módulo) y ruby.conf generado por nosotros. Ahora cómo mod_ruby  ejecuta los scrips de ruby como CGI necesitamos poner la directiva Options +ExecCGI en el folder dónde vamos a poner nuestros scripts, en mi caso particular necesito que todos los usuarios del sistema puedan ejecutar sus scripts desde su ~/public_html entonces para lograr esto tenemos que editar la configuración del módulo user_dir, editamos el archivo</p>
<pre>vi /etc/apache2/mods-available/userdir.conf
<pre>y agregamos lo siguiente:
<pre> &lt;IfModule mod_userdir.c&gt;
        UserDir public_html
        UserDir disabled root

        &lt;Directory /home/*/public_html&gt;
                AllowOverride FileInfo AuthConfig Limit Indexes
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                # Para poder ejecutar scripts en ruby agregamos la linea de abajo
                Options +ExecCGI
                &lt;Limit GET POST OPTIONS&gt;
                        Order allow,deny
                        Allow from all
                &lt;/Limit&gt;
                &lt;LimitExcept GET POST OPTIONS&gt;
                        Order deny,allow
                        Deny from all
                &lt;/LimitExcept&gt;
        &lt;/Directory&gt;
&lt;/IfModule&gt;</pre>
</pre>
</pre>
<p>No sé si esto muy seguro o tiene alguna consecuencia no deseada, si es así comenten!<br />
Bueno ahora sólo necesitamos habilitar el móludo para esto ejecutamos el siguiente comando:</p>
<p>a2enmod ruby</p>
<p>y hacemos un reload del apache</p>
<p>/etc/init.d apache2 reload</p>
<p>despues de esto para probarlo ponemos un archivo en nuestro home</p>
<p>vi /home/gaston/test-ruby.rb</p>
<p>con un simple:</p>
<pre>puts 'hello world'</pre>
<p>vamos al navegador a la siguiente url:</p>
<p>http://aca-va-la-url-de-tuserver/~gaston/test-ruby.rb</p>
<p>y vamos a ver un hermoso ‘hello world’ si todo salió bien.</p>
<p>Bueno, con mod_ruby solo para escribir una página web dinámica vamos a tener que hacer algo cómo esto:</p>
<p>puts ‘&lt;h1&gt;Mi Título&lt;/h1&gt;’</p>
<p>lo cual es muy molesto, para hacer las cosas un póco más lindas y más fácil debemos usar eruby que nos permite ejecutar código ruby dentro de archivos de text (como por ejémplo un arhivo html)</p>
<p>Entonces comencemos por instalar eruby:</p>
<pre>apt-get install eruby</pre>
<p>y luego tenemos que modificar nuevamente el archivo /etc/apache2/mods-available/ruby.conf de esta manera:</p>
<pre>&lt;IfModule mod_ruby.c&gt;
  RubyRequire apache/ruby-run
  RubyRequire apache/eruby-run

  &lt;Files *.rbx&gt;
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  &lt;/Files&gt;

 &lt;Files *.rhtml&gt;
  SetHandler ruby-object
  RubyHandler Apache::ERubyRun.instance
 &lt;/Files&gt;

&lt;/IfModule&gt;</pre>
<p>Y luego debemos agregar la siguiente directiva al archivo de configuración de apache /etc/apache2/apache2.conf</p>
<pre>AddType text/html .rhtml</pre>
<p>Con esto recargamos el apache y ya podemos escribir nuestros .rhtml<br />
y poner código ruby entre los tags &lt;%= %&gt;</p>
<p><strong>Links útiles:</strong></p>
<p>http://en.wikipedia.org/wiki/ERuby<br />
http://wiki.modruby.net/ja/?InstallGuide<br />
http://modruby.net/<br />
http://ubuntuforums.org/archive/index.php/t-356350.html<br />
http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gastonramos.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gastonramos.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gastonramos.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gastonramos.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gastonramos.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gastonramos.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gastonramos.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gastonramos.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gastonramos.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gastonramos.wordpress.com/328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gastonramos.wordpress.com&#038;blog=1034400&#038;post=328&#038;subd=gastonramos&#038;ref=&#038;feed=1" /></div>
<p>&#8220;</p>
<p>(Via <a href="http://gastonramos.wordpress.com">Gastón Ramos &#8211; Ruby, Rails&#8230;</a>.) Original Link: <a href="http://gastonramos.wordpress.com/2009/04/22/instalando-mod_ruby/#comments">Instalando Mod_Ruby</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7949681675937032";
google_ad_slot = "0874687580";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mundoruby.com.ar/2009/04/22/instalando-mod_ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

