<?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>MyFunnyDev &#187; Ruby</title>
	<atom:link href="http://michalkuklis.com/blog/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://michalkuklis.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 14 Jan 2012 17:45:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>rendering generic views in rails 3</title>
		<link>http://michalkuklis.com/blog/2010/09/27/rendering-generic-views-rails-3/</link>
		<comments>http://michalkuklis.com/blog/2010/09/27/rendering-generic-views-rails-3/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 12:40:16 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=313</guid>
		<description><![CDATA[# serve mustache templates class TemplatesController &#60; ActionController::Metal &#160; # include render functionality &#160; include ActionController::Rendering &#160; append_view_path Rails.root.join&#40;&#34;app&#34;, &#34;views&#34;&#41; &#160; def serve &#160; &#160; if env&#91;&#34;PATH_INFO&#34;&#93; =~ /^\/templates\/&#40;.+&#41;$/ &#160; &#160; &#160; key = $1 &#160; &#160; &#160; &#160; &#160; &#160; begin &#160; &#160; &#160; &#160; render :file =&#62; &#34;templates/properties/_#{key}.html.mustache&#34; &#160; &#160; &#160; rescue &#160; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:700px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># serve mustache templates</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> TemplatesController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Metal</span><br />
&nbsp; <span style="color:#008000; font-style:italic;"># include render functionality</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Rendering</span><br />
<br />
&nbsp; append_view_path Rails.<span style="color:#9900CC;">root</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;app&quot;</span>, <span style="color:#996600;">&quot;views&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> serve<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;PATH_INFO&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^\<span style="color:#006600; font-weight:bold;">/</span>templates\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span><br />
&nbsp; &nbsp; &nbsp; key = $1 &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;templates/properties/_#{key}.html.mustache&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">status</span> = <span style="color:#ff3333; font-weight:bold;">:file_not_found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">content_type</span> = <span style="color:#996600;">'text/plain'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">response_body</span> = <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">status</span> = <span style="color:#ff3333; font-weight:bold;">:file_not_found</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">content_type</span> = <span style="color:#996600;">'text/plain'</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">response_body</span> = <span style="color:#996600;">''</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2010/09/27/rendering-generic-views-rails-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>managing gems with rvm named gem sets</title>
		<link>http://michalkuklis.com/blog/2010/05/30/managing-gems-with-rvm-named-gem-sets/</link>
		<comments>http://michalkuklis.com/blog/2010/05/30/managing-gems-with-rvm-named-gem-sets/#comments</comments>
		<pubDate>Mon, 31 May 2010 03:20:44 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=298</guid>
		<description><![CDATA[RVM (Ruby Version Manager) is a tool which lets you install and switch between multiple ruby versions. RVM has also something called Named Gem Sets. This is pretty cool because you can create many different gem sets for different types of apps. Here is how to do it (I assume you have rvm already installed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rvm.beginrescueend.com/">RVM (Ruby Version Manager)</a> is a tool which lets you install and switch between multiple ruby versions. RVM has also something called <a href="http://rvm.beginrescueend.com/gemsets/basics/">Named Gem Sets</a>. This is pretty cool because you can create many different gem sets for different types of apps. Here is how to do it (I assume you have rvm already installed if not check <a href="http://rvm.beginrescueend.com/rvm/install/">this</a> out):</p>
<ul>
<li>go to your project folder and create new file called .<strong>rvmrc</strong></li>
<li>open .rvmrc and add rvm ruby-version@your-gem-set for example <strong>rvm ruby-1.9.1@railsgems</strong></li>
<li>close file and type: <strong>rvm gemset create your-gem-set </strong>(this will create new set)</li>
<li>type gem list (you should see empty list with no gems installed)</li>
</ul>
<p>It&#8217;s almost as you would start with a fresh system.</p>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2010/05/30/managing-gems-with-rvm-named-gem-sets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dfs in ruby :)</title>
		<link>http://michalkuklis.com/blog/2010/01/14/bfs-in-ruby/</link>
		<comments>http://michalkuklis.com/blog/2010/01/14/bfs-in-ruby/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 05:38:42 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=277</guid>
		<description><![CDATA[I wrote simple dfs in ruby: def dfs&#40;node, value, queue&#41; &#160; return false if node.nil? &#160; return true if node.data == value &#160; &#160; queue.push node.right unless node.right.nil? &#160; queue.push node.left unless node.left.nil?&#160; &#160; &#160; dfs&#40;queue.pop, value, queue&#41;&#160; end for node: class Node &#160; attr_accessor :left, :right, :data end]]></description>
			<content:encoded><![CDATA[<p>I wrote simple dfs in ruby:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> dfs<span style="color:#006600; font-weight:bold;">&#40;</span>node, value, queue<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">if</span> node.<span style="color:#0000FF; font-weight:bold;">nil</span>? <br />
&nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#9966CC; font-weight:bold;">if</span> node.<span style="color:#9900CC;">data</span> == value<br />
&nbsp; <br />
&nbsp; queue.<span style="color:#9900CC;">push</span> node.<span style="color:#9900CC;">right</span> <span style="color:#9966CC; font-weight:bold;">unless</span> node.<span style="color:#9900CC;">right</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; queue.<span style="color:#9900CC;">push</span> node.<span style="color:#9900CC;">left</span> <span style="color:#9966CC; font-weight:bold;">unless</span> node.<span style="color:#9900CC;">left</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?&nbsp; <br />
&nbsp; <br />
&nbsp; dfs<span style="color:#006600; font-weight:bold;">&#40;</span>queue.<span style="color:#9900CC;">pop</span>, value, queue<span style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; <br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>for node:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Node<br />
&nbsp; attr_accessor <span style="color:#ff3333; font-weight:bold;">:left</span>, <span style="color:#ff3333; font-weight:bold;">:right</span>, <span style="color:#ff3333; font-weight:bold;">:data</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2010/01/14/bfs-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>class variables, class instance variables and instance variables in ruby</title>
		<link>http://michalkuklis.com/blog/2010/01/13/class-variable-class-instance-variables-and-instance-variables-in-ruby/</link>
		<comments>http://michalkuklis.com/blog/2010/01/13/class-variable-class-instance-variables-and-instance-variables-in-ruby/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 06:03:22 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=270</guid>
		<description><![CDATA[This was covered multiple times already. I&#8217;ve created this little snippet to remember the difference between different types of variables in ruby: class A &#160; @@foo = &#34;class variable of the class A&#34; &#160; @foo = &#34;class instance variable of the class A&#34; &#160; &#160; def instance_method &#160; &#160;@foo = &#34;instance variable of the class [...]]]></description>
			<content:encoded><![CDATA[<p>This was covered multiple times already. I&#8217;ve created this little snippet to remember the difference between different types of variables in ruby:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:700px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> A<br />
&nbsp; @@foo = <span style="color:#996600;">&quot;class variable of the class A&quot;</span><br />
&nbsp; <span style="color:#0066ff; font-weight:bold;">@foo</span> = <span style="color:#996600;">&quot;class instance variable of the class A&quot;</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> instance_method<br />
&nbsp; &nbsp;<span style="color:#0066ff; font-weight:bold;">@foo</span> = <span style="color:#996600;">&quot;instance variable of the class A&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">class_method1</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># class variables are visible to and shared by the instance and class methods</span><br />
&nbsp; &nbsp; @@foo<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">class_method2</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># class instance variables are visible to and shared by the class methods</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@foo</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> <br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">p</span> A.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">instance_method</span> <span style="color:#008000; font-style:italic;"># instance variable of the class A</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> A.<span style="color:#9900CC;">class_method1</span> <span style="color:#008000; font-style:italic;"># class variable of the class A</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> A.<span style="color:#9900CC;">class_method2</span> <span style="color:#008000; font-style:italic;"># class instance variable of the class A</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> B <span style="color:#006600; font-weight:bold;">&lt;</span> A<br />
&nbsp; @@foo = <span style="color:#996600;">&quot;class variable of the class B&quot;</span><br />
&nbsp; <span style="color:#0066ff; font-weight:bold;">@foo</span> = <span style="color:#996600;">&quot;class instance variable of the class B&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">p</span> B.<span style="color:#9900CC;">class_method1</span> <span style="color:#008000; font-style:italic;"># class variable in B</span><br />
<span style="color:#008000; font-style:italic;"># class variable in A is overwritten by one in B !!!</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> A.<span style="color:#9900CC;">class_method1</span> <span style="color:#008000; font-style:italic;"># class variable in B</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">p</span> B.<span style="color:#9900CC;">class_method2</span> <span style="color:#008000; font-style:italic;"># class instance variable of the class B</span><br />
<span style="color:#008000; font-style:italic;"># class instance variable in A is NOT overwritten by one in B !!!</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> A.<span style="color:#9900CC;">class_method2</span> <span style="color:#008000; font-style:italic;"># class instance variable of the class A</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2010/01/13/class-variable-class-instance-variables-and-instance-variables-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>anemone with hpricot</title>
		<link>http://michalkuklis.com/blog/2010/01/11/anemone-with-hpricot/</link>
		<comments>http://michalkuklis.com/blog/2010/01/11/anemone-with-hpricot/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 05:06:32 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=265</guid>
		<description><![CDATA[Anemone is a pretty cool DSL used for web crawling. I used it with Hpricot to get a feeling for what&#8217;s possible. Below is a simple example which crawls and scrappes data from a popular polish real estate website otodom: require 'rubygems' require 'sanitize' require 'anemone' require 'open-uri' require 'hpricot' #otodom.pl Anemone.crawl&#40;&#34;http://otodom.pl/index.php?mod=search&#38;act=searchResults&#38;qid=46911208&#34;, &#123;:storage =&#62; Anemone::Storage.PStore&#40;&#34;crawl1.pstore&#34;&#41;&#125;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><a title="anemone" href="http://anemone.rubyforge.org/">Anemone</a> is a pretty cool DSL used for web crawling. I used it with <a title="hpricot" href="http://github.com/whymirror/hpricot">Hpricot</a> to get a feeling for what&#8217;s possible. Below is a simple example which crawls and scrappes data from a popular polish real estate website <a title="otodom" href="http://otodom.pl/">otodom</a>:</p>
<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:700px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sanitize'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'anemone'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hpricot'</span><br />
<br />
<span style="color:#008000; font-style:italic;">#otodom.pl</span><br />
Anemone.<span style="color:#9900CC;">crawl</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://otodom.pl/index.php?mod=search&amp;act=searchResults&amp;qid=46911208&quot;</span>, <br />
<span style="color:#006600; font-weight:bold;">&#123;</span>:storage <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Anemone::Storage</span>.<span style="color:#CC00FF; font-weight:bold;">PStore</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;crawl1.pstore&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> anemone <span style="color:#006600; font-weight:bold;">|</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># filter out useless pages</span><br />
&nbsp; anemone.<span style="color:#9900CC;">focus_crawl</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>page<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp;page.<span style="color:#9900CC;">links</span>.<span style="color:#9900CC;">delete_if</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>x.<span style="color:#9900CC;">to_s</span> =~ <span style="color:#006600; font-weight:bold;">/</span>mod=search<span style="color:#006600; font-weight:bold;">&amp;</span>act=searchResults<span style="color:#006600; font-weight:bold;">&amp;</span>qid=<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>x.<span style="color:#9900CC;">to_s</span> =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>zA<span style="color:#006600; font-weight:bold;">-</span>Z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+-</span>id<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\.<span style="color:#9900CC;">html</span>$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;"># process details pages</span><br />
&nbsp; anemone.<span style="color:#9900CC;">on_pages_like</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>zA<span style="color:#006600; font-weight:bold;">-</span>Z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+-</span>id<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\.<span style="color:#9900CC;">html</span>$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> page <span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp;doc = Hpricot<span style="color:#006600; font-weight:bold;">&#40;</span>page.<span style="color:#9900CC;">doc</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;price = &nbsp;doc.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//strong[@id='offerPrice']&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;location = doc.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//dl[@class='stripeMe'] &gt; dd&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;desc = doc.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//div[@id='offerDesc'] &gt; p&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;offer_no = doc.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//div[@id='offerFoot'] p[@class='toLeft']/span/strong&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;created_at = doc.<span style="color:#9900CC;">at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//div[@id='offerFoot'] p[@class='toRight']/span/strong&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;photos = doc.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//div[@id='imageList']/p/a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2010/01/11/anemone-with-hpricot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>blocks, procs and lambdas in ruby</title>
		<link>http://michalkuklis.com/blog/2009/11/17/blocks-procs-and-lambdas-in-ruby/</link>
		<comments>http://michalkuklis.com/blog/2009/11/17/blocks-procs-and-lambdas-in-ruby/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 04:12:20 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=252</guid>
		<description><![CDATA[Nice post about block, procs and lambdas in ruby by Robert Sosinski.]]></description>
			<content:encoded><![CDATA[<p>Nice post <a href="http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/">about block, procs and lambdas in ruby</a> by Robert Sosinski.</p>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/11/17/blocks-procs-and-lambdas-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby maxins in rails plugins</title>
		<link>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/</link>
		<comments>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:16:46 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=175</guid>
		<description><![CDATA[Very often when looking at the code in rails plugins you can run into this: module Taggable def self.included&#40;base&#41; base.extend&#40;ClassMethods&#41; end module module ClassMethods #methods here end end This is a part of a bigger pattern which is shown below: module ModuleA def self.included&#40;base&#41; # add class methods from ModuleB base.extend&#40;ModuleB&#41; end end &#160; module [...]]]></description>
			<content:encoded><![CDATA[<p>Very often when looking at the code in rails plugins you can run into this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span class="kw1">module</span> Taggable 
  <span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
    base.<span class="me1">extend</span><span class="br0">&#40;</span>ClassMethods<span class="br0">&#41;</span>
  <span class="kw1">end</span>
  <span class="kw1">module</span> <span class="kw1">module</span> ClassMethods
    <span class="co1">#methods here</span>
  <span class="kw1">end</span>
<span class="kw1">end</span></pre></div></div>

<p>This is a part of a bigger pattern which is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span class="kw1">module</span> ModuleA
  <span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
    <span class="co1"># add class methods from ModuleB</span>
    base.<span class="me1">extend</span><span class="br0">&#40;</span>ModuleB<span class="br0">&#41;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">module</span> ModuleB
  <span class="kw1">def</span> act_as_hello
    <span class="kw3">p</span> <span class="st0">&quot;hello from module B&quot;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">class</span> ClassC
 <span class="co1">#class body here</span>
<span class="kw1">end</span>
&nbsp;
<span class="co1"># include moduleA in classC</span>
ClassC.<span class="me1">send</span><span class="br0">&#40;</span>:<span class="kw1">include</span>, ModuleA<span class="br0">&#41;</span>
&nbsp;
<span class="kw1">class</span> ClassD <span class="sy0">&lt;</span> ClassC
  act_as_hello
<span class="kw1">end</span>
&nbsp;
classD = ClassD.<span class="me1">new</span></pre></div></div>

<p>The pattern is used often when developing plugins with ActiveRecord. What we gain by inheriting from ClassC  (<b>class ClassD < ClassC</b>) are instance methods from ModuleA. This is done by:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">ClassC.<span class="me1">send</span><span class="br0">&#40;</span>:<span class="kw1">include</span>, ModuleA<span class="br0">&#41;</span></pre></div></div>

<p>Moreover since ModuleA is included in ClassC, ModuleA&#8217;s initializer <strong>def self.included(base)</strong> will be invoked at the time  ModuleA is mixed with ClassC. The invocation will call <b>base.extend(ModuleB)</b>. In this case <b>base</b> represents ClassC which will be extended by adding class methods from ModuleB. The ModuleA&#8217;s init method is shown again below:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span class="kw1">def</span> <span class="kw2">self</span>.<span class="me1">included</span><span class="br0">&#40;</span>base<span class="br0">&#41;</span>
  <span class="co1"># add class methods from ModuleB to ClassC</span>
  base.<span class="me1">extend</span><span class="br0">&#40;</span>ModuleB<span class="br0">&#41;</span>
<span class="kw1">end</span></pre></div></div>

<p>At the end our ClassD has now access to all class methods defined in ModuleB.  <strong>act_as_hello</strong> will be called during ClassD initialization:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span class="kw1">class</span> ClassD <span class="sy0">&lt;</span> ClassC
  act_as_hello
<span class="kw1">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/07/20/ruby-maxins-in-rails-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class and Instance Variables In Ruby</title>
		<link>http://michalkuklis.com/blog/2009/06/13/class-and-instance-variables-in-ruby/</link>
		<comments>http://michalkuklis.com/blog/2009/06/13/class-and-instance-variables-in-ruby/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 04:27:11 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=163</guid>
		<description><![CDATA[nice post about class and instance vars in ruby.]]></description>
			<content:encoded><![CDATA[<p>nice post about <a href="http://railstips.org/2006/11/18/class-and-instance-variables-in-ruby">class and instance vars in ruby</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/06/13/class-and-instance-variables-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>few more ruby links</title>
		<link>http://michalkuklis.com/blog/2009/05/18/few-more-ruby-links/</link>
		<comments>http://michalkuklis.com/blog/2009/05/18/few-more-ruby-links/#comments</comments>
		<pubDate>Mon, 18 May 2009 23:24:42 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=160</guid>
		<description><![CDATA[class and instance methods include vs extend again]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://railstips.org/2009/5/11/class-and-instance-methods-in-ruby">class and instance methods</a></li>
<li><a href="http://railstips.org/2009/5/15/include-verse-extend-in-ruby">include vs extend again </a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/05/18/few-more-ruby-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>going back to ruby again&#8230;</title>
		<link>http://michalkuklis.com/blog/2009/04/04/go-back-to-ruby-again/</link>
		<comments>http://michalkuklis.com/blog/2009/04/04/go-back-to-ruby-again/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 18:05:00 +0000</pubDate>
		<dc:creator>Michał Kuklis</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://michalkuklis.com/blog/?p=148</guid>
		<description><![CDATA[Here are few links which helped me understand few ruby concepts: include vs extend include,extend,module_eval,class_eval anonymous classes (aka singleton classes) ruby-metaprogramming-techniques]]></description>
			<content:encoded><![CDATA[<p>Here are few links which helped me understand few ruby concepts:</p>
<ul>
<li><a href="http://www.fromjavatoruby.com/2008/10/include-vs-extend.html">include vs extend</a></li>
<li><a href="http://neeraj.name/blog/articles/503-include-extend-module_eval-class_eval">include,extend,module_eval,class_eval</a></li>
<li><a href="http://pmade.com/articles/2008/ruby-singleton">anonymous classes (aka singleton classes)</a></li>
<li><a href="http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html">ruby-metaprogramming-techniques</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://michalkuklis.com/blog/2009/04/04/go-back-to-ruby-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

