<?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>Bicosyes - since evermore... &#187; Ruby</title>
	<atom:link href="http://bicosyes.com/category/programacion/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://bicosyes.com</link>
	<description></description>
	<lastBuildDate>Sat, 06 Mar 2010 20:03:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to know, in ruby, which methods have been added and by whom?</title>
		<link>http://bicosyes.com/how-to-know-in-ruby-which-methods-have-been-added-and-by-whom/</link>
		<comments>http://bicosyes.com/how-to-know-in-ruby-which-methods-have-been-added-and-by-whom/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 19:50:37 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[method_added]]></category>
		<category><![CDATA[monkeypatching]]></category>

		<guid isPermaLink="false">http://bicosyes.com/?p=885</guid>
		<description><![CDATA[If you are not very careful, monkeypatching could be very harmful. One thing to remember is that you should never override a method to add funcionality, for those kind of thinks you must use alias chain method pattern, a safer way of doing that. 
For the rest of the monkeypatching, i.e. add new methods, you [...]]]></description>
			<content:encoded><![CDATA[<p>If you are not very careful, monkeypatching could be very harmful. One thing to remember is that you should <strong>never</strong> override a method to <strong>add</strong> funcionality, for those kind of thinks you must use <em>alias chain method pattern</em>, a safer way of doing that. </p>
<p>For the rest of the <em>monkeypatching</em>, i.e. add new methods, you could debug them really easy with something like this:</p>
<pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> method_added<span style="color:#006600; font-weight:bold;">&#40;</span>method_name<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{method_name} added to #{self}, callstack:&quot;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">caller</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span>|line| <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>#{line}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
<p>You can always add more code to filter by class or by method's name. Let's see an example:</p>
<pre class="ruby">$ more example.<span style="color:#9900CC;">rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'date'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'time'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> method_added<span style="color:#006600; font-weight:bold;">&#40;</span>method_name<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#9966CC; font-weight:bold;">if</span> %w<span style="color:#006600; font-weight:bold;">&#40;</span>method_added<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? method_name.<span style="color:#9900CC;">to_s</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{method_name} added to #{self}, callstack:&quot;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">caller</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span>|line| <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>#{line}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> to_date
      <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">ordinal</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">year</span>, <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">yday</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Date</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> to_time
      <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">parse</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">to_s</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;to_date not working&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span>
   <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_date</span> == <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">today</span>
<span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;to time not working&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span>
   <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_date</span>.<span style="color:#9900CC;">to_time</span> == <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">today</span>.<span style="color:#9900CC;">to_time</span></pre>
<p>The output will be:</p>
<pre>$ ruby example.rb
to_date added to Time, callstack:
	example.rb:13
to_time added to Date, callstack:
	example.rb:19</pre>
<p>Nice, isn't it?. Remember to be carefull with your monkeypatching, with great power comes great responsibility, it's just a tool, neither magic nor the panacea.</p>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=885&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/how-to-know-in-ruby-which-methods-have-been-added-and-by-whom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualización de la documentación de todas las gemas instaladas</title>
		<link>http://bicosyes.com/visualizacion-de-la-documentacion-de-todas-las-gemas-instaladas/</link>
		<comments>http://bicosyes.com/visualizacion-de-la-documentacion-de-todas-las-gemas-instaladas/#comments</comments>
		<pubDate>Sun, 31 May 2009 12:55:10 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bdoc]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rdoc]]></category>

		<guid isPermaLink="false">http://bicosyes.com/?p=835</guid>
		<description><![CDATA[La documentación de las gemas de ruby se genera a partir del código fuente mediante rdoc. Después de eso puedes optar por ver individualmente cada una o usar gem server.
Para poder mejorar todo esto podemos usar par de útiles herramientas: (1) la plantilla para rdoc, hanna; y (2)bdoc como alternativa a gem server para visualizar [...]]]></description>
			<content:encoded><![CDATA[<p>La documentación de las gemas de ruby se genera a partir del código fuente mediante rdoc. Después de eso puedes optar por ver individualmente cada una o usar <a href="http://rubygems.org/read/chapter/18">gem server</a>.</p>
<p>Para poder mejorar todo esto podemos usar par de útiles herramientas: (1) la plantilla para rdoc, <strong><a href="http://github.com/mislav/hanna/tree/master">hanna</a></strong>; y (2)<a href="http://manalang.com/archives/2009/03/29/introducing-bdoc-a-better-gem-doc-browser/"><strong>bdoc</strong></a> como alternativa a gem server para visualizar la documentación.</p>
<p><strong>Hanna</strong> es una plantilla para rdoc que mejora notablemente el formato por defecto. Podemos ver la diferencia fácilmente, por ejemplo, en la documentación de rspec con <a href="http://rspec.rubyforge.org/rspec/1.1.11/">el formato típico</a> <em>vs</em> <a href="http://rspec.rubyforge.org/rspec/1.2.6/">la documentación hecha con hanna</a>. La instalación es simple:</p>
<pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem sources -a http://gems.github.com
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mislav-hanna</pre>
<p>Para que a partir de ahora se generar la documentación con esta plantilla, puede añadir a tu <em>.gemrc</em> la siguiente línea:</p>
<pre>rdoc: --inline-source --line-numbers --template=hanna</pre>
<p>Y para convertir la documentación de todas tus gemas instaladas, puedes hacer algo como esto:</p>
<pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem list | <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span> | <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> hanna --gems</pre>
<p>Por otro lado, gracias a <strong>bdoc</strong> podremos navegar fácilmente entre todas las documentaciones.</p>
<pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> manalang-bdoc
$ bdoc</pre>
<p><a href="http://bicosyes.com/wp-content/uploads/2009/05/bdoc.jpg"><img src="http://bicosyes.com/wp-content/uploads/2009/05/bdoc-300x157.jpg" alt="bdoc" title="bdoc" width="300" height="157" class="aligncenter size-medium wp-image-836" /></a><br />
Ejecutando <em>bdoc</em> se nos abrirá en nuestro navegador por defecto listo para poder leer la documentación y poder movernos fácilmente entre las diferentes gemas (y versiones). Muy útil.</p>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=835&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/visualizacion-de-la-documentacion-de-todas-las-gemas-instaladas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 2.2 &amp; Inflector &amp; Dependencies</title>
		<link>http://bicosyes.com/rails-22-inflector-dependencies/</link>
		<comments>http://bicosyes.com/rails-22-inflector-dependencies/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 06:08:55 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bicosyes.com/?p=702</guid>
		<description><![CDATA[Si has actualizado a rails 2.2 (o superior) desde una versión previa puedes encontrarte con un par de errores típicos con una solución muy simple: 

`const_missing': uninitialized constant Rails::Plugin::Dependencies (NameError)

Es debido a que Dependencies ahora es ActiveSupport::Dependencies.

`load_missing_constant': uninitialized constant Inflector (NameError)

Es debido a que Inflector ahora es ActiveSupport::Inflector. Por lo que ahora puedes usar las [...]]]></description>
			<content:encoded><![CDATA[<p>Si has actualizado a rails 2.2 (o superior) desde una versión previa puedes encontrarte con un par de errores típicos con una solución muy simple: </p>
<blockquote><p>
`const_missing': uninitialized constant Rails::Plugin::Dependencies (NameError)
</p></blockquote>
<p>Es debido a que <em>Dependencies</em> ahora es <em>ActiveSupport::Dependencies</em>.</p>
<blockquote><p>
`load_missing_constant': uninitialized constant Inflector (NameError)
</p></blockquote>
<p>Es debido a que <em>Inflector</em> ahora es <em>ActiveSupport::Inflector</em>. Por lo que ahora puedes usar las <em>inflections</em> tal que así:</p>
<pre class="ruby">&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActiveSupport::Inflector</span>.<span style="color:#9900CC;">inflections</span> <span style="color:#9966CC; font-weight:bold;">do</span> |inflect|
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=702&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/rails-22-inflector-dependencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bot personal jabber para twitter, RTwittBot</title>
		<link>http://bicosyes.com/bot-personal-jabber-para-twitter-rtwittbot/</link>
		<comments>http://bicosyes.com/bot-personal-jabber-para-twitter-rtwittbot/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 15:03:29 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[twitter4r]]></category>
		<category><![CDATA[xmpp]]></category>
		<category><![CDATA[xmpp4r]]></category>

		<guid isPermaLink="false">http://bicosyes.com/?p=645</guid>
		<description><![CDATA[Desde hace ya un tiempo llevo usando twitter, y no, no tiene ninguna utilidad, pero me gusta hablar solo (¡está loco!). Twitter se cae cada dos por tres, pero era algo que se puede soportar (así siempre tienes algo que decir... y de lo que quejarte que a todos nos gusta quejarnos, ¡quejicas!), pero desde [...]]]></description>
			<content:encoded><![CDATA[<p>Desde hace ya un tiempo llevo usando <a href="http://twitter.com/blaxter">twitter</a>, y no, no tiene ninguna utilidad, pero me gusta hablar solo (¡está loco!). <a href="http://status.twitter.com">Twitter</a> se cae cada dos por tres, pero era algo que se puede soportar (así siempre tienes algo que decir... y de lo que quejarte que a todos nos gusta quejarnos, ¡quejicas!), pero desde Mayo desactivaron el servicio que tenían de <strong>mensajería instantánea</strong> (¡como el colacao!) por <strong>jabber</strong>.</p>
<p>Mediante ese servicio de <strong>IM</strong> jabber teníamos el <strong>bot</strong> de twitter al cual podíamos:</p>
<ul>
<li>Mandar mensajes para postear en nuestro twitter</li>
<li>Recibir mensajes de nuestro <em>timeline</em> de la gente que seguíamos y teníamos marcada como <em>follow</em></li>
</ul>
<p>Es decir, ahorrarnos el tener que entrar a la puta página y tener que estar dándole a <em>f5</em> todo el rato. Para mi esto es un <strong>requisito</strong> para usar twitter. Si no es por IM, no lo usaría. </p>
<p>Estuve un tiempo en <a href="http://blaxter.jaiku.com">jaiku</a> (más que nada porque era el único servicio similar que tenía el IM activado, <a href="http://plurk.com">plurk</a>, que es molón, molón; también lo desactivó) pero ahora se ha vuelto tonto y empieza a funcionar mal. Así que pensé un poquito y dije, <em>¡leches, pero si te puedes montar un bot jabber en 4 pipas!</em>, dicho y hecho, <a href="http://twitter.com/blaxter/statuses/899569373">volví a twitter</a> creándome un bot jabber, en <a href="http://www.ruby-lang.org/es/">ruby</a>, que hace justo la misma funcionalidad que el de twitter "<em>oficial</em>" (aunque es solo para <strong>una</strong> persona obviamente, <img src='http://bicosyes.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). </p>
<p>Lo he llamado <strong><a href="http://github.com/blaxter/rtwittbot">RTwittBot</a></strong> (feo de cojones, lo sé), el código <a href="http://github.com/blaxter/rtwittbot">está en github</a>, para hacerlo funcionar solo necesitas tener ruby y algunas gemas que he indicado en el <em>README</em> en github. Naturalmente, necesitarás una cuenta <em>jabber</em> para que sea usada por el bot (por ejemplo cualquier cuenta que tengas de gmail sirve) aparte de la tuya propia que ya usas, todo esto se encuentra explicado en github.</p>
<p>Por ahora lo llevo usando unos días y es bastante estable, e incluso si ocurre algún fallo en el propio bot (twitter caído, bug en el código, etc...) el bot no debería caerse sino que cambia su disponibilidad a <em>away</em> e indica en su estado el porqué, para volver a cambiarlo cuando todo vuelve a la normalidad <img src='http://bicosyes.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>Cualquier duda sobre su uso o lo que sea, deja un comentario <img src='http://bicosyes.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=645&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/bot-personal-jabber-para-twitter-rtwittbot/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Rails </title>
		<link>http://bicosyes.com/rails-2-1-con-ruby-1-8-7-broken/</link>
		<comments>http://bicosyes.com/rails-2-1-con-ruby-1-8-7-broken/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:08:33 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bicosyes.com/?p=643</guid>
		<description><![CDATA[Es muy peligroso, de locos más bien (o aventureros), usar últimas versiones (aka debian testing/unstable) únicamente de ciertas "cosas" (llámese cosas a librerías, paquetes, lenguajes, etc...). 
Me he encontrado con un problema curioso debido al uso del interprete de ruby en una de sus últimas versiones estables (1.8.7) con el framework rails en una versión [...]]]></description>
			<content:encoded><![CDATA[<p>Es muy peligroso, de locos más bien (o aventureros), usar últimas versiones (<acronym title="also known as">aka</acronym> debian testing/unstable) únicamente de ciertas "cosas" (llámese <em>cosas</em> a librerías, paquetes, lenguajes, etc...). </p>
<p>Me he encontrado con un problema curioso debido al uso del interprete de ruby en una de sus <a href="http://packages.debian.org/sid/ruby1.8">últimas versiones estables (1.8.7)</a> con el framework rails en una versión que no es la última (2.0.2).</p>
<p>Habría que mencionar que rails 2.0.2 salió en diciembre del año pasado, mientras que <a href="http://www.ruby-lang.org/en/news/2008/05/31/ruby-1-8-7-has-been-released/">ruby 1.8.7 es de apenas mes y medio</a> por lo que es comprensible el fallo.</p>
<p>El problema está en que en ruby 1.8.7 se han añadido muchas cosas nuevas, como, por ejemplo, el método <em>chars</em> a la clase <em>String</em>:</p>
<pre class="ruby">&nbsp;
$ ruby -v
ruby <span style="color:#006666;">1.8</span><span style="color:#006666;">.7</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2008</span><span style="color:#006666;">-05</span><span style="color:#006666;">-31</span> patchlevel <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>i486-linux<span style="color:#006600; font-weight:bold;">&#93;</span>
$ irb
&gt;&gt; foo = <span style="color:#996600;">&quot;I love popcorns&quot;</span>.<span style="color:#9900CC;">chars</span>
=&gt; <span style="color:#008000; font-style:italic;">#&lt;Enumerable::Enumerator:0xb7c0206c&gt;</span>
&gt;&gt; foo.<span style="color:#9900CC;">first</span>.<span style="color:#9966CC; font-weight:bold;">class</span>
=&gt; <span style="color:#CC0066; font-weight:bold;">String</span></pre>
<p>Método inspirado en el activesupport de rails:</p>
<pre class="ruby">&nbsp;
$ ruby -v
ruby <span style="color:#006666;">1.8</span><span style="color:#006666;">.6</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2007</span><span style="color:#006666;">-09</span><span style="color:#006666;">-24</span> patchlevel <span style="color:#006666;">111</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>i486-linux<span style="color:#006600; font-weight:bold;">&#93;</span>
$ irb
&gt;&gt; <span style="color:#996600;">&quot;Hello world?&quot;</span>.<span style="color:#9900CC;">chars</span>
<span style="color:#CC00FF; font-weight:bold;">NoMethodError</span>: undefined method <span style="color:#996600;">'chars'</span> <span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#996600;">&quot;Hello world?&quot;</span><span style="color:#ff3333; font-weight:bold;">:String</span>
$ cd /some/rails/project/ &amp;&amp; script/console
Loading development environment <span style="color:#006600; font-weight:bold;">&#40;</span>Rails <span style="color:#006666;">2.0</span><span style="color:#006666;">.2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&gt;&gt; <span style="color:#996600;">&quot;Hola hola&quot;</span>.<span style="color:#9900CC;">chars</span>
=&gt; <span style="color:#008000; font-style:italic;">#&lt;ActiveSupport::Multibyte::Chars:0xb74d0050 @string=&quot;Hola hola&quot;&gt;</span></pre>
<p>Es decir, en rails se definía un método que devolvía un <em>ActiveSupport::Multibyte::Chars</em>, pero si ejecutamos en un interprete 1.8.7 nos encontraremos que al ejecutar el método <em>chars</em> de una <em>String</em>, nos devolverá un <em>Enumerator</em> por lo que ahí ya puede pasar de todo (mayormente porque son cosas diferentes y así mal asunto). </p>
<pre class="ruby"><span style="color:#6666ff; font-weight:bold;">ActionView::TemplateError</span>: undefined method <span style="color:#996600;">'[]'</span> <span style="color:#9966CC; font-weight:bold;">for</span> <span style="color:#008000; font-style:italic;">#&lt;Enumerable::Enumerator:0xb6f3481c&gt;</span></pre>
<p>La solución, si queremos seguir usando rails 2.0.2, es realmente simple. Si no queremos pensar, podemos ver <a href="http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/string/unicode.rb">cómo lo han solucionado en el HEAD de rails</a>. Y simplemente añadimos esta solución en algún initializer (por ejemplo en <em>config/initializers/fixes.rb</em>):</p>
<pre class="rails">&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
 	<span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#006600; font-weight:bold;">&#123;</span> remove_method <span style="color:#ff3333; font-weight:bold;">:chars</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">NameError</span>
	<span style="color:#008000; font-style:italic;"># all Ok</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
<p>De esta forma, nos eliminará el método <em>chars</em> de <em>String</em> y podemos usar <a href="http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/string/unicode.rb#L38">el definido en ActiveSupport</a> en la metaclase de <em>String</em>. Es decir, como si aquí no hubiera pasado nada. </p>
<p>Por cierto, hay otros temas similares en cuanto a compatibilidad con ruby 1.8.7, relacionados con <a href="http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb#L7">String#start_with?/end_with?</a> y <a href="http://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext/enumerable.rb#L5">Enumarable#group_by</a> pero mucho más simples y no tan "graves".</p>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=643&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/rails-2-1-con-ruby-1-8-7-broken/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Autocompletado e historial de métodos en la consola de ruby (irb)</title>
		<link>http://bicosyes.com/autocompletado-e-historial-de-metodos-en-la-consola-de-ruby-irb/</link>
		<comments>http://bicosyes.com/autocompletado-e-historial-de-metodos-en-la-consola-de-ruby-irb/#comments</comments>
		<pubDate>Fri, 16 May 2008 14:16:14 +0000</pubDate>
		<dc:creator>blaxter</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://bicosyes.com/autocompletado-e-historial-de-metodos-en-la-consola-de-ruby-irb/</guid>
		<description><![CDATA[Hoy le toca el turno a ruby. La consola de ruby, irb, tiene bastantes opciones de configuración, permitiendo, entre otras cosas, el autocompletado de métodos e incluso guardar un historial de comandos entre sesiones. 
Muy simple, simplemente añade esto a tu fichero ~/.irbrc (si no existe, lo creas):
equire 'irb/completion'
&#160;
IRB.conf&#91;:SAVE_HISTORY&#93; = 1000
IRB.conf&#91;:HISTORY_FILE&#93; = &#34;#{ENV['HOME']}/.irb-save-history&#34;
IRB.conf&#91;:AUTO_INDENT&#93;  = [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy le toca el turno a <strong>ruby</strong>. La consola de ruby, <strong>irb</strong>, tiene <a href="http://www.rubycentral.com/pickaxe/irb.html">bastantes opciones</a> de configuración, permitiendo, entre otras cosas, el autocompletado de métodos e incluso guardar un historial de comandos entre sesiones. </p>
<p>Muy simple, simplemente añade esto a tu fichero ~/.irbrc (si no existe, lo creas):</p>
<pre class="ruby">equire <span style="color:#996600;">'irb/completion'</span>
&nbsp;
IRB.<span style="color:#9900CC;">conf</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:SAVE_HISTORY</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006666;">1000</span>
IRB.<span style="color:#9900CC;">conf</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:HISTORY_FILE</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;#{ENV['HOME']}/.irb-save-history&quot;</span>
IRB.<span style="color:#9900CC;">conf</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:AUTO_INDENT</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = <span style="color:#0000FF; font-weight:bold;">true</span>
IRB.<span style="color:#9900CC;">conf</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:PROMPT_MODE</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = <span style="color:#ff3333; font-weight:bold;">:SIMPLE</span></pre>
<p>Puedes añadir otras opciones, e incluso personalizar el <em>prompt</em> el cual lo tengo a '<em>simple</em>' porque los otros modos son demasiado informativos para mi gusto (nunca he entendido esa manía de querer incorporar siempre el número de comando en todas las consolas de los lenguajes).</p>
<img src="http://bicosyes.com/?ak_action=api_record_view&id=631&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://bicosyes.com/autocompletado-e-historial-de-metodos-en-la-consola-de-ruby-irb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
