<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Plan A</title>
	<atom:link href="http://theplana.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://theplana.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<pubDate>Sun, 30 Mar 2008 20:09:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>StrongRuby : gradual typing for Duby.</title>
		<link>http://theplana.wordpress.com/2008/03/30/strongruby-gradual-typing-for-duby/</link>
		<comments>http://theplana.wordpress.com/2008/03/30/strongruby-gradual-typing-for-duby/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 20:07:23 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[GSoC]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[WTF]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[ideas]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/?p=76</guid>
		<description><![CDATA[Abstract :
&#160;
 Static and dynamic type systems have well-known strengths and weaknesses.  Statically typed programming languages incorporate a built-in static type system. Every legal program must successfully typecheck according to the rules of the type system. 
&#160;
 Gradual typing provides the benefits of both static and dynamic checking in a single language by allowing [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify"><font face="Bitstream Charter, serif"><b><font size="3">Abstract :</font></b></font></p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify">&nbsp;</p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify"> <font face="Bitstream Charter, serif"><font size="2">Static and dynamic type systems have well-known strengths and weaknesses.  Statically typed programming languages incorporate a built-in static type system. Every legal program must successfully typecheck according to the rules of the type system. </font></font></p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify">&nbsp;</p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify"> <font face="Bitstream Charter, serif"><font size="2">Gradual typing provides the benefits of both static and dynamic checking in a single language by allowing the programmer to control whether a portion of the program is type checked at compile-time or run-time by adding or removing type annotations on variables. , that have no effect on the dynamic semantics of the language. </font></font></p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify">&nbsp;</p>
<p style="margin-left:2.51cm;margin-right:2.53cm;margin-bottom:0;" align="justify">The complete proposal here : <b><a href="http://theplana.files.wordpress.com/2008/03/strongruby.pdf" title="strongruby.pdf">strongruby.pdf</a></b></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/76/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/76/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=76&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2008/03/30/strongruby-gradual-typing-for-duby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby idioms : Avoid check class membership</title>
		<link>http://theplana.wordpress.com/2008/03/09/ruby-idioms-avoid-check-class-membership/</link>
		<comments>http://theplana.wordpress.com/2008/03/09/ruby-idioms-avoid-check-class-membership/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 10:54:16 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[bad smell]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[ruby commom bugs]]></category>

		<category><![CDATA[ruby idioms]]></category>

		<category><![CDATA[smellcode]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/?p=70</guid>
		<description><![CDATA[Avoid use class, is_a? and  kind_of?  to check class membership. Replace these statement with a message to the object that respond to the message. The code below is an anti-pattern.



if mortgage.class==FixRateMortgage
   mortgage.change_rate_not_allowed
else
   mortgage.rate=rate
end


The code below is more idiomatic in Ruby.



class Mortgage
  attr_accessor :rate
end 

class FixedRateMortgage &#60; Mortgage
  [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Avoid use <b>class, <a href="http://ruby-doc.org/core/classes/Object.html#M000370">is_a?</a></b> and <a href="http://ruby-doc.org/core/classes/Object.html#M000370"><b> kind_of?</b></a>  to check class membership. Replace these statement with a message to the object that respond to the message. The code below is an anti-pattern.</p>
<div class="CodeRay">
<div class="code">
<pre>
<span style="color:#008800;font-weight:bold;">if</span> mortgage.class==<span style="color:#003366;font-weight:bold;">FixRateMortgage</span>
   mortgage.change_rate_not_allowed
<span style="color:#008800;font-weight:bold;">else</span>
   mortgage.rate=rate
<span style="color:#008800;font-weight:bold;">end</span></pre>
</div>
</div>
<p>The code below is more idiomatic in Ruby.</p>
<div class="CodeRay">
<div class="code">
<pre>
<span style="color:#008800;font-weight:bold;">class</span> <span style="color:#bb0066;font-weight:bold;">Mortgage</span>
  attr_accessor <span style="color:#aa6600;">:rate</span>
<span style="color:#008800;font-weight:bold;">end</span> 

<span style="color:#008800;font-weight:bold;">class</span> <span style="color:#bb0066;font-weight:bold;">FixedRateMortgage</span> &lt; <span style="color:#003366;font-weight:bold;">Mortgage</span>
  <span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">initialize</span>()
    <span style="color:#3333bb;">@rate</span>=<span style="color:#0000dd;font-weight:bold;">5</span>
  <span style="color:#008800;font-weight:bold;">end</span>
  <span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">rate=</span>(rate)
    change_rate_not_allowed
  <span style="color:#008800;font-weight:bold;">end</span>

  <span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">change_rate_not_allowed</span>
     puts <span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">The rate in a fixed rate mortage can not be change</span><span style="color:#771100;">"</span></span>
  <span style="color:#008800;font-weight:bold;">end</span>
<span style="color:#008800;font-weight:bold;">end</span></pre>
</div>
</div>
<p>Sending the method rate= to either kind of classes will result in the appropriate behaviour.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/70/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/70/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=70&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2008/03/09/ruby-idioms-avoid-check-class-membership/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Commons bugs in ruby: blocks and local variables</title>
		<link>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-blocks-and-local-variables/</link>
		<comments>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-blocks-and-local-variables/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 17:22:05 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[bad smell]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[smellcode]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/?p=69</guid>
		<description><![CDATA[Originally blocks did not have truly local variables.  The block
parameters were really local variables in the enclosing method.


x=0
1.upto 100 do &#124;z&#124;
  x = x+z
end
x  #=&#62; 5050 



       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Originally blocks did not have truly local variables.  The block<br />
parameters were really local variables in the enclosing method.</p>
<div class="CodeRay">
<div class="code">
<pre>x=<span style="color:#00D;font-weight:bold;">0</span>
<span style="color:#00D;font-weight:bold;">1</span>.upto <span style="color:#00D;font-weight:bold;">100</span> <span style="color:#080;font-weight:bold;">do</span> |z|
  x = x+z
<span style="color:#080;font-weight:bold;">end</span>
x  <span style="color:#888;">#=&gt; 5050 </span>
</pre>
</div>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/69/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/69/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=69&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-blocks-and-local-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Commons bugs in ruby: Changing collection while iterating over it</title>
		<link>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-changing-collection-while-iterating-over-it/</link>
		<comments>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-changing-collection-while-iterating-over-it/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 17:19:24 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[bad smell]]></category>

		<category><![CDATA[ruby commom bugs]]></category>

		<category><![CDATA[smellcode]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-changing-collection-while-iterating-over-it/</guid>
		<description><![CDATA[You should never, never, never iterate over a collection which the iteration loop somehow modifies. Elements of the collection will be moved during the iteration. Elements might be missed or handled twice.


 b=(1..10).collect # =&#62; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 b.each do &#124;elem&#124;
   b.delete elem
 end #=&#62; [2, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>You should never, never, never iterate over a collection which the iteration loop somehow modifies. Elements of the collection will be moved during the iteration. Elements might be missed or handled twice.</p>
<div class="CodeRay">
<div class="code">
<pre> b=(<span style="color:#00D;font-weight:bold;">1</span>..<span style="color:#00D;font-weight:bold;">10</span>).collect <span style="color:#888;"># =&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</span>
 b.each <span style="color:#080;font-weight:bold;">do</span> |elem|
   b.delete elem
 <span style="color:#080;font-weight:bold;">end</span> <span style="color:#888;">#=&gt; [2, 4, 6, 8, 10]</span>
</pre>
</div>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/68/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/68/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=68&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2008/03/06/commons-bugs-in-ruby-changing-collection-while-iterating-over-it/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Snippet: remove .svn directories</title>
		<link>http://theplana.wordpress.com/2007/09/23/snippet-remove-svn-directories/</link>
		<comments>http://theplana.wordpress.com/2007/09/23/snippet-remove-svn-directories/#comments</comments>
		<pubDate>Sun, 23 Sep 2007 22:56:24 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[code]]></category>

		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/09/23/snippet-remove-svn-directories/</guid>
		<description><![CDATA[  find . -name ".svn" -exec rm -rf {} \;
via Mongrel list &#8212; Zed Shaw
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><code>  find . -name ".svn" -exec rm -rf {} \;</code></p>
<p>via Mongrel list &#8212; Zed Shaw</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/66/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/66/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=66&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/09/23/snippet-remove-svn-directories/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby idioms : Add a method to a concrete instance.</title>
		<link>http://theplana.wordpress.com/2007/09/17/ruby-idioms-add-a-method-to-a-concrete-instance/</link>
		<comments>http://theplana.wordpress.com/2007/09/17/ruby-idioms-add-a-method-to-a-concrete-instance/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 15:53:45 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[ruby idioms]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/09/17/ruby-idioms-add-a-method-to-a-concrete-instance/</guid>
		<description><![CDATA[Sometimes can be useful to add a method in a specific instance of a class. We can do that with the next code :


 class Person
 end 

 pedro = Person.new
 peter = Person.new

 # inject a method in the instances
 def pedro.hello_world; puts &#34;Hola Mundo&#34;; end

 def peter.hello_world; puts &#34;Hello World&#34;; end 

 pedro.hello_world [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes can be useful to add a method in a specific instance of a class. We can do that with the next code :</p>
<div class="CodeRay">
<div class="code">
<pre> <span style="color:#080;font-weight:bold;">class</span> <span style="color:#B06;font-weight:bold;">Person</span>
 <span style="color:#080;font-weight:bold;">end</span> 

 pedro = <span style="color:#036;font-weight:bold;">Person</span>.new
 peter = <span style="color:#036;font-weight:bold;">Person</span>.new

 <span style="color:#666;"># inject a method in the instances</span>
 <span style="color:#080;font-weight:bold;">def</span> pedro.hello_world; puts <span style="background-color:#fff0f0;"><span style="color:#710;">&quot;</span><span style="color:#D20;">Hola Mundo</span><span style="color:#710;">&quot;</span></span>; <span style="color:#080;font-weight:bold;">end</span>

 <span style="color:#080;font-weight:bold;">def</span> peter.hello_world; puts <span style="background-color:#fff0f0;"><span style="color:#710;">&quot;</span><span style="color:#D20;">Hello World</span><span style="color:#710;">&quot;</span></span>; <span style="color:#080;font-weight:bold;">end</span> 

 pedro.hello_world <span style="color:#666;">#=&gt; Hola Mundo</span>
 peter.hello_world <span style="color:#666;">#=&gt; Hello World</span>
</pre>
</div>
</div>
<p>A more useful example, an Array that represent a list of employees that must be sortable by any of the employee attributes : (via Neal Ford) </p>
<div class="CodeRay">
<div class="code">
<pre>  employees  = []
  <span style="color:#080;font-weight:bold;">def</span> employees.sort_by_attribute(sym)
    sort {|x, y| x.send(sym) &lt;=&gt; y.send(sym)}
  <span style="color:#080;font-weight:bold;">end</span>
</pre>
</div>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/64/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/64/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=64&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/09/17/ruby-idioms-add-a-method-to-a-concrete-instance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamics finders in ActiveRecord using AOP.</title>
		<link>http://theplana.wordpress.com/2007/09/17/dynamics-finders-in-activerecord-using-aop/</link>
		<comments>http://theplana.wordpress.com/2007/09/17/dynamics-finders-in-activerecord-using-aop/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 00:05:21 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[aop]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/09/17/dynamics-finders-in-activerecord-using-aop/</guid>
		<description><![CDATA[Yesterday, I have been playing with Aquarium, an AOP framework for ruby. I decided hack a little bit. I try to refactor the dynamics finders of ActiveRecord, using an AOP approach.
First lets try to understand what are and how dynamics finders works.
This are queries are equvalent :


User.find(:first, :conditions =&#62; ["name = ?", name])
User.find_by_name(name)

User.find(:all, :conditions =&#62; [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday, I have been playing with <a href="http://aquarium.rubyforge.org/">Aquarium,</a> an AOP framework for ruby. I decided hack a little bit. I try to refactor the dynamics finders of ActiveRecord, using an AOP approach.</p>
<p>First lets try to understand <a href="http://blog.hasmanythrough.com/2006/8/13/how-dynamic-finders-work">what are and how dynamics finders works.</a></p>
<p>This are queries are equvalent :</p>
<p class="CodeRay">
<p class="code">
<pre><span style="color:#003366;font-weight:bold;">User</span>.find(<span style="color:#aa6600;">:first</span>, <span style="color:#aa6600;">:conditions</span> =&gt; [<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">name = ?</span><span style="color:#771100;">"</span></span>, name])
<span style="color:#003366;font-weight:bold;">User</span>.find_by_name(name)

<span style="color:#003366;font-weight:bold;">User</span>.find(<span style="color:#aa6600;">:all</span>, <span style="color:#aa6600;">:conditions</span> =&gt; [<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">city = ?</span><span style="color:#771100;">"</span></span>, city])
<span style="color:#003366;font-weight:bold;">User</span>.find_all_by_city(city)

<span style="color:#003366;font-weight:bold;">User</span>.find(<span style="color:#aa6600;">:all</span>, <span style="color:#aa6600;">:conditions</span> =&gt; [<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">street = ? AND city IN (?)</span><span style="color:#771100;">"</span></span>, street, cities])
<span style="color:#003366;font-weight:bold;">User</span>.find_all_by_street_and_city(street, cities)</pre>
<p>And how this cool methods are generated? They are not generated, ActiveRecords use a bit of the method_missing magic to parse the method_name to find a pattern. A simplify version of the method_missing :</p>
<p class="CodeRay">
<p class="code">
<pre><span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">method_missing</span>(method_id, *arguments)
  <span style="color:#008800;font-weight:bold;">if</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">find_(all_by|by)_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span><span style="color:#880088;">*)</span><span style="color:#440044;">/</span></span>.match(method_id.to_s)
    <span style="color:#666666;"># find...</span>
  <span style="color:#008800;font-weight:bold;">elsif</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">find_or_create_by_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span><span style="color:#880088;">*)</span><span style="color:#440044;">/</span></span>.match(method_id.to_s)
    <span style="color:#666666;"># find_or_create...</span>
  <span style="color:#008800;font-weight:bold;">else</span>
    <span style="color:#008800;font-weight:bold;">super</span>
  <span style="color:#008800;font-weight:bold;">end</span>
<span style="color:#008800;font-weight:bold;">end</span></pre>
<p>Now its time to introduce the AOP in the recipe. We create two advices, the pointcut is the method missing. This two advices perform as a chain, first the last defined.</p>
<p class="CodeRay">
<p class="code">
<pre><span style="color:#008800;font-weight:bold;">class</span> <span style="color:#bb0066;font-weight:bold;">Base</span>
    before <span style="color:#aa6600;">:method</span>=&gt;<span style="color:#aa6600;">:method_missing</span> <span style="color:#008800;font-weight:bold;">do</span> |this, execution_point, *args|
        <span style="color:#008800;font-weight:bold;">if</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">^find_(all_by|by)_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span><span style="color:#880088;">*)$</span><span style="color:#440044;">/</span></span>.match(args.fir st.to_s)
            <span style="color:#666666;"># find_by_xxx... #do something smart and break the flow</span>
        <span style="color:#008800;font-weight:bold;">end</span>
    <span style="color:#008800;font-weight:bold;">end</span>

    before <span style="color:#aa6600;">:method</span>=&gt;<span style="color:#aa6600;">:method_missing</span> <span style="color:#008800;font-weight:bold;">do</span> |this, execution_point, *args|
        <span style="color:#008800;font-weight:bold;">if</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">^find_or_(initialize|create)_by_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span><span style="color:#880088;">*)$</span><span style="color:#440044;">/</span></span>. match(args.first.to_s)
          <span style="color:#666666;"># find_or_xxx #do something smart and break the flow</span>
        <span style="color:#008800;font-weight:bold;">end</span>
    <span style="color:#008800;font-weight:bold;">end</span>

  <span style="color:#666666;"># And so on, until you have a minimum common behaviour or an empty method_missing.   </span>
<span style="color:#008800;font-weight:bold;">end</span></pre>
<p>We can extract more behaviour from the method missing, We can repeat this process until we have the minimum common behaviour or a empty method_missing. Sometimes we neer to break the chain at some point. In this cases we can uses around.</p>
<p>One of the benefits of this approach is that will be more easy to introduce new finder in rails. Currently to create a new finder we need to create a plugin in the vendor folder. For example we are going to create a find_like finder. We write our code in the vendor/plugins/find_like/lib/find_like.rb :</p>
<p class="CodeRay">
<p class="code">
<pre><span style="color:#008800;font-weight:bold;">module</span> <span style="color:#bb0066;font-weight:bold;">ActiveRecord</span>
  <span style="color:#008800;font-weight:bold;">class</span> <span style="color:#bb0066;font-weight:bold;">Base</span>
    <span style="color:#008800;font-weight:bold;">class</span> &lt;&lt; <span style="color:#bb0066;font-weight:bold;">self</span>
      private
      alias_method <span style="color:#aa6600;">:previous_method_missing</span>, <span style="color:#aa6600;">:method_missing</span>
     <span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">method_missing</span>(method_id, *arguments)
        <span style="color:#008800;font-weight:bold;">if</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">find_(all_like|like)_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span>o<span style="color:#880088;">*)</span><span style="color:#440044;">/</span></span>.match(method_id.to_s)
          <span style="color:#666666;"> # do something smart </span>
        <span style="color:#008800;font-weight:bold;">else</span>
          previous_method_missing(method_id, *arguments)
        <span style="color:#008800;font-weight:bold;">end</span>
      <span style="color:#008800;font-weight:bold;">end</span>
    <span style="color:#008800;font-weight:bold;">end</span>
  <span style="color:#008800;font-weight:bold;">end</span>
<span style="color:#008800;font-weight:bold;">end</span></pre>
<p>If we use the AOP approach we need to write, also our code in the vendor/plugins/find_like/lib :</p>
<p class="CodeRay">
<p class="code">
<pre><span style="color:#008800;font-weight:bold;">module</span> <span style="color:#bb0066;font-weight:bold;">FinderLike</span>
 <span style="color:#666666;"># A custom finder finder_like_xxx</span>
 before <span style="color:#aa6600;">:types</span> =&gt; <span style="color:#aa6600;">:Base</span>, <span style="color:#aa6600;">:methods</span> =&gt;<span style="color:#aa6600;">:method_missing</span> <span style="color:#008800;font-weight:bold;">do</span> |execution_point,  *args|
   <span style="color:#008800;font-weight:bold;">if</span> match = <span style="background-color:#fff0ff;"><span style="color:#440044;">/</span><span style="color:#880088;">find_(all_like|like)_([_a-zA-Z]</span><span style="color:#0044dd;">\w</span><span style="color:#880088;">*)</span><span style="color:#440044;">/</span></span>.match(args.first.to_s)
     <span style="color:#666666;"># Do something smart and break the flow     </span>
   <span style="color:#008800;font-weight:bold;">end</span>
 <span style="color:#008800;font-weight:bold;">end</span>
<span style="color:#008800;font-weight:bold;">end</span></pre>
<p>I Don&#8217;t know if this is a good design in this particular case. But at least was a funny Kata.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/63/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/63/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=63&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/09/17/dynamics-finders-in-activerecord-using-aop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>blocks parameters list and metaprogramming</title>
		<link>http://theplana.wordpress.com/2007/09/16/blocks-parameters-list-and-metaprogramming/</link>
		<comments>http://theplana.wordpress.com/2007/09/16/blocks-parameters-list-and-metaprogramming/#comments</comments>
		<pubDate>Sun, 16 Sep 2007 20:39:31 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[api design]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/09/16/blocks-parameters-list-and-metaprogramming/</guid>
		<description><![CDATA[I have been playing with a Aquarium, the new AOP framework in Ruby.   A point advice is create for example : 



before :type=&#62;A, :method=&#62;:foo do &#124;execution_point, *args&#124;
  self.some_method() # call a class method from A
  other_method()     # call other class method from A
  # call a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been playing with a Aquarium, the new AOP framework in Ruby.   A point advice is create for example : </p>
<div class="CodeRay">
<div class="code">
<pre>
before <span style="color:#A60;">:type</span>=&gt;<span style="color:#036;font-weight:bold;">A</span>, <span style="color:#A60;">:method</span>=&gt;<span style="color:#A60;">:foo</span> <span style="color:#080;font-weight:bold;">do</span> |execution_point, *args|
  <span style="color:#038;font-weight:bold;">self</span>.some_method() <span style="color:#666;"># call a class method from A</span>
  other_method()     <span style="color:#666;"># call other class method from A</span>
  <span style="color:#666;"># call a method from the caller object</span>
  execution_point.context.advised_object.bar()
<span style="color:#080;font-weight:bold;">end</span>
</pre>
</div>
</div>
<p>The DSL is nice but i found the access to the caller object is a tedious. I prefer something like this : </p>
<div class="CodeRay">
<div class="code">
<pre>before <span style="color:#A60;">:type</span>=&gt;<span style="color:#036;font-weight:bold;">A</span>, <span style="color:#A60;">:method</span>=&gt;<span style="color:#A60;">:foo</span> <span style="color:#080;font-weight:bold;">do</span> |execution_point,this , *args|
  <span style="color:#038;font-weight:bold;">self</span>.some_method() <span style="color:#666;"># call a class method from A</span>
  other_method()     <span style="color:#666;"># call other class method from A</span>
  <span style="color:#666;"># call a method from the caller object</span>
  this.bar()
<span style="color:#080;font-weight:bold;">end</span>
</pre>
</div>
</div>
<p>Dean Wampier think thats would be great if the user could specify combinations<br />
like these:</p>
<blockquote><p>       |join_point, the_self, *method_args|<br />
       |join_point|<br />
       |the_self|<br />
       |the_self, *method_args|<br />
       |join_point, the_self|<br />
       |join_point, *method_args|</p></blockquote>
<p>But the point is that the advices is create in the &#8220;definition time class&#8221; using some code generation at<br />
runtime. How can i know the arity of the argument list. </p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#080;font-weight:bold;">module</span> <span style="color:#B06;font-weight:bold;">Kernel</span>
  <span style="color:#080;font-weight:bold;">def</span> <span style="color:#06B;font-weight:bold;">before</span> (name, &amp;block)
    define_method(name){
      <span style="color:#080;font-weight:bold;">if</span> block.arity == <span style="color:#00D;font-weight:bold;">1</span>
        <span style="color:#080;font-weight:bold;">yield</span> <span style="color:#A60;">:only_one</span>
      <span style="color:#080;font-weight:bold;">elsif</span>  block.arity == <span style="color:#00D;font-weight:bold;">2</span>
        <span style="color:#080;font-weight:bold;">yield</span> <span style="color:#A60;">:one</span>,<span style="color:#A60;">:two</span>
      <span style="color:#080;font-weight:bold;">elsif</span> block.arity == <span style="color:#00D;font-weight:bold;">-2</span>
        <span style="color:#080;font-weight:bold;">yield</span> <span style="color:#A60;">:one</span>, <span style="color:#A60;">:a</span> , <span style="color:#A60;">:splater</span>, <span style="color:#A60;">:argument</span>
      <span style="color:#080;font-weight:bold;">end</span>
    }
  <span style="color:#080;font-weight:bold;">end</span>
<span style="color:#080;font-weight:bold;">end</span>

<span style="color:#080;font-weight:bold;">class</span> <span style="color:#B06;font-weight:bold;">A</span>
  before <span style="color:#A60;">:foo</span> <span style="color:#080;font-weight:bold;">do</span> |first|
    puts first
  <span style="color:#080;font-weight:bold;">end</span>
<span style="color:#080;font-weight:bold;">end</span>

a = <span style="color:#036;font-weight:bold;">A</span>.new
a.foo

<span style="color:#080;font-weight:bold;">class</span> <span style="color:#B06;font-weight:bold;">A</span>
  before <span style="color:#A60;">:foo</span> <span style="color:#080;font-weight:bold;">do</span> |first , second|
    puts second
  <span style="color:#080;font-weight:bold;">end</span>
<span style="color:#080;font-weight:bold;">end</span>

a2 = <span style="color:#036;font-weight:bold;">A</span>.new
a2.foo

<span style="color:#080;font-weight:bold;">class</span> <span style="color:#B06;font-weight:bold;">A</span>
  before <span style="color:#A60;">:foo</span> <span style="color:#080;font-weight:bold;">do</span> |first , *splat_arg|
    puts splat_arg
  <span style="color:#080;font-weight:bold;">end</span>
<span style="color:#080;font-weight:bold;">end</span>

a3 = <span style="color:#036;font-weight:bold;">A</span>.new
a3.foo
</pre>
</div>
</div>
<p>Thats great, the block can be acceded because its a Proc class. Now we can predict the number of parameter of that the user has write and create a more friendly DSL. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/62/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/62/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=62&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/09/16/blocks-parameters-list-and-metaprogramming/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Default values and Hash parameters</title>
		<link>http://theplana.wordpress.com/2007/08/28/default-values-and-hash-parameters/</link>
		<comments>http://theplana.wordpress.com/2007/08/28/default-values-and-hash-parameters/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 02:54:53 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[ruby idioms]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/08/28/default-values-and-hash-parameters/</guid>
		<description><![CDATA[I had talked before about it. We can use a hash to pass parameter to our method, and que can merge with another hash that contain the defaults values.  Why to do that :

Set Default Values in Methods : Avoid unexpected behaviour.
Simple Hash as Default Method Parameter : This form allows you to add [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I had talked before about it. We can use a hash to pass parameter to our method, and que can merge with another hash that contain the defaults values.  Why to do that :</p>
<ul>
<li><strong>Set Default Values in Methods </strong>: Avoid unexpected behaviour.</li>
<li><strong>Simple Hash as Default Method Parameter</strong> : This form allows you to add functionality to methods without breaking existing calls</li>
</ul>
<pre><span style="color:#008800;font-weight:bold;">def</span> <span style="color:#0066bb;font-weight:bold;">add_book</span>(p_arg)

  p_arg = {:title=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">no title</span><span style="color:#771100;">", </span></span><span style="color:#aa6600;"></span></pre>
<pre><span style="color:#aa6600;">           :author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">anonymous</span><span style="color:#771100;">"</span></span>,</pre>
<pre>           <span style="color:#aa6600;">:language</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">esperanto</span><span style="color:#771100;">"</span></span>}.merge! p_arg

<span style="color:#008800;font-weight:bold;">end</span></pre>
<pre>add_book <span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>,</pre>
<pre>         <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes"</span><span style="color:#771100;"></span></span>,</pre>
<pre>         <span style="color:#aa6600;">:language</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">spanish</span><span style="color:#771100;">"</span></span>

=&gt; {<span style="color:#aa6600;">:language</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">spanish</span><span style="color:#771100;">"</span></span>, <span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>, <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes</span><span style="color:#771100;">"</span></span>}</pre>
<pre>
add_book <span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>,</pre>
<pre>         <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes</span><span style="color:#771100;">"</span></span>

=&gt; {<span style="color:#aa6600;">:language</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">esperanto</span><span style="color:#771100;">"</span></span>, <span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>, <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes</span><span style="color:#771100;">"</span></span>}</pre>
<pre>
add_book <span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>,</pre>
<pre>         <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes</span><span style="color:#771100;">"</span></span></pre>
<pre>         <span style="color:#aa6600;">:foo</span>=&gt;<span style="color:#aa6600;">:bar</span>

=&gt; {<span style="color:#aa6600;">:language</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">esperanto</span><span style="color:#771100;">"</span></span>, :foo=&gt;"bar" ,<span style="color:#aa6600;">:title</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">El Qujote</span><span style="color:#771100;">"</span></span>, <span style="color:#aa6600;">:author</span>=&gt;<span style="background-color:#fff0f0;"><span style="color:#771100;">"</span><span style="color:#dd2200;">Miguel De Cervantes</span><span style="color:#771100;">"</span></span>}</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/61/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/61/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=61&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/08/28/default-values-and-hash-parameters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ramdon tips for Rails</title>
		<link>http://theplana.wordpress.com/2007/08/24/ramdon-tips-for-rails/</link>
		<comments>http://theplana.wordpress.com/2007/08/24/ramdon-tips-for-rails/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 12:39:10 +0000</pubDate>
		<dc:creator>Pedro</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://theplana.wordpress.com/2007/08/24/ramdon-tips-for-rails/</guid>
		<description><![CDATA[
MVC as a constraint
Over do MVC
Don&#8217;t put any code in the view
Don&#8217;t do any DB operation in the controller
Set Default Values in Methods : Avoid unexpected behaviour.
Simple Hash as Default Method Parameter : This form allows you to add functionality to methods without breaking existing calls
Helpers are hard to test, its will turn Rails into [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><ul>
<li>MVC as a <span style="font-style:italic;">constraint</span></li>
<li>Over do MVC</li>
<li>Don&#8217;t put any code in the view</li>
<li>Don&#8217;t do any DB operation in the controller</li>
<li>Set Default Values in Methods : Avoid unexpected behaviour.</li>
<li>Simple Hash as Default Method Parameter : This form allows you to add functionality to methods without breaking existing calls</li>
<li>Helpers are hard to test, its will turn Rails into PHP</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/theplana.wordpress.com/60/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/theplana.wordpress.com/60/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theplana.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theplana.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theplana.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theplana.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theplana.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theplana.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theplana.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theplana.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theplana.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theplana.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theplana.wordpress.com&blog=732868&post=60&subd=theplana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theplana.wordpress.com/2007/08/24/ramdon-tips-for-rails/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>