<?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>Railstic &#187; ruby</title>
	<atom:link href="http://railstic.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://railstic.com</link>
	<description>sharing experiences</description>
	<lastBuildDate>Mon, 29 Aug 2011 00:31:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Dynamically Defining Methods with define_method</title>
		<link>http://railstic.com/2011/06/dynamically-defining-methods-with-define_method/</link>
		<comments>http://railstic.com/2011/06/dynamically-defining-methods-with-define_method/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 23:08:08 +0000</pubDate>
		<dc:creator>İ. Emre Kutlu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[define_method]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[singleton class]]></category>

		<guid isPermaLink="false">http://railstic.com/?p=190</guid>
		<description><![CDATA[If you have been hacking ruby for a while you should have heard that &#8220;Everything is an object&#8221;. To understand this concept knowing what a singleton class is important. Yehuda Katz&#8217;s post is a good source for it. My ruby version 1.9.2. First I&#8217;m going to show you how to add methods to instances by using [...]]]></description>
			<content:encoded><![CDATA[<p>If you have been hacking ruby for a while you should have heard that &#8220;Everything is an object&#8221;. To understand this concept knowing what a <strong>singleton class</strong> is important. <a href="http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/" target="_blank">Yehuda Katz&#8217;s post</a> is a good source for it.</p>
<p>My ruby version 1.9.2.</p>
<div id="gist-1009449" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nv">$ </span>ruby -v</div><div class='line' id='LC2'>ruby 1.9.2p136 <span class="o">(</span>2010-12-25 revision 30365<span class="o">)</span> <span class="o">[</span>i686-linux<span class="o">]</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1009449/8655aae42c2a00cc5bb1b72d2387221964b62ce1/ruby_version.bash" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1009449#file_ruby_version.bash" style="float:right;margin-right:10px;color:#666">ruby_version.bash</a>
            <a href="https://gist.github.com/1009449">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>First I&#8217;m going to show you how to add methods to instances by using <code><strong>define_method</strong></code>.</p>
<p><script src="https://gist.github.com/1009449.js?file=add_instance_methods.rb"></script></p>
<p>You can also write an instance method to create instance methods. <code><strong>send</strong></code> must be used because <code><strong>define_method</strong></code> is private.</p>
<p><script src="https://gist.github.com/1009449.js?file=add_instance_methods_by_instance_method.rb"></script></p>
<p>Write a singleton method to create instance methods.</p>
<p><script src="https://gist.github.com/1009449.js?file=add_instance_methods_by_singleton_method.rb"></script></p>
<p>Now it is time to add singleton methods. When we call <code><strong>define_method</strong></code>, it creates an instance method. What we have to do is call <code><strong>define_method</strong></code> on class&#8217; singleton class.</p>
<p>Getting singleton class of a class:</p>
<p><script src="https://gist.github.com/1009449.js?file=get_singleton_class.rb"></script></p>
<p>First defining singleton method to create singleton methods.</p>
<p><script src="https://gist.github.com/1009449.js?file=add_singleton_methods_by_singleton_method.rb"></script></p>
<p>Then defining instance method to create singleton methods.</p>
<p><script src="https://gist.github.com/1009449.js?file=add_singleton_methods_by_instance_method.rb"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://railstic.com/2011/06/dynamically-defining-methods-with-define_method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating RubyGems to 1.2 (Manually)</title>
		<link>http://railstic.com/2008/08/updating-rubygems-to-12-manually/</link>
		<comments>http://railstic.com/2008/08/updating-rubygems-to-12-manually/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 12:34:50 +0000</pubDate>
		<dc:creator>İ. Emre Kutlu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://izzetemrekutlu.com/blog/?p=45</guid>
		<description><![CDATA[This is what happened when I want to install rmagick gem. username@username-desktop:~$ sudo gem install rmagick Bulk updating Gem source index for: http://gems.rubyforge.org/ ERROR: could not find rmagick locally or in a repository What the hell&#8230; After some googling I found that RubGems 1.1.x is buggy and and update to RubyGems 1.2 is necessary. To [...]]]></description>
			<content:encoded><![CDATA[<p>
This is what happened when I want to install rmagick gem.<br />
</p>

<div class="wp_codebox"><table><tr id="p457"><td class="code" id="p45code7"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick
Bulk updating Gem <span style="color: #7a0874; font-weight: bold;">source</span> index <span style="color: #000000; font-weight: bold;">for</span>: http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>
ERROR:  could not <span style="color: #c20cb9; font-weight: bold;">find</span> rmagick locally or <span style="color: #000000; font-weight: bold;">in</span> a repository</pre></td></tr></table></div>

<p>
What the hell&#8230;<br />
After some googling I found that RubGems 1.1.x is buggy and and update to RubyGems 1.2 is necessary.<br />
To learn your RubyGems version:<br />
</p>

<div class="wp_codebox"><table><tr id="p458"><td class="code" id="p45code8"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~$ gem <span style="color: #660033;">-v</span>
1.1.0</pre></td></tr></table></div>

<p><span id="more-45"></span><br />
 I try to update RubyGems :<br />
</p>

<div class="wp_codebox"><table><tr id="p459"><td class="code" id="p45code9"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem update <span style="color: #660033;">--system</span>
Updating RubyGems
Bulk updating Gem <span style="color: #7a0874; font-weight: bold;">source</span> index <span style="color: #000000; font-weight: bold;">for</span>: http:<span style="color: #000000; font-weight: bold;">//</span>gems.rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>
Nothing to update</pre></td></tr></table></div>

<p>
After this failed attempt, I realized that RubyGems 1.1.x is really buggy. So I must go on manually to update RubyGems.<br />
<br />
<strong>Now the solution:</strong><br />
</p>
<ol>
<li>
Download <a href="http://rubyforge.org/frs/download.php/38844/rubygems-update-1.2.0.gem">rubygems-update-1.2.0.gem</a>
</li>
<li>
Change your directory where your downloaded gem is. In these example my gem is at Desktop.<br />
Now you must install <em>rubygems-update-1.2.0.gem</em>.</p>

<div class="wp_codebox"><table><tr id="p4510"><td class="code" id="p45code10"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~$ <span style="color: #7a0874; font-weight: bold;">cd</span> Desktop<span style="color: #000000; font-weight: bold;">/</span>
username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~<span style="color: #000000; font-weight: bold;">/</span>Desktop$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rubygems-update-1.2.0.gem</pre></td></tr></table></div>

</li>
<li>

<div class="wp_codebox"><table><tr id="p4511"><td class="code" id="p45code11"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~<span style="color: #007800;">$sudo</span> update_rubygems</pre></td></tr></table></div>

</li>
</ol>
<p>
To check if our process is successful :<br />
</p>

<div class="wp_codebox"><table><tr id="p4512"><td class="code" id="p45code12"><pre class="bash" style="font-family:monospace;">username<span style="color: #000000; font-weight: bold;">@</span>username-desktop:~<span style="color: #007800;">$gem</span> <span style="color: #660033;">-v</span>
1.2.0</pre></td></tr></table></div>

<p>
If you see <em>1.2.0</em>, you did it.</p>
]]></content:encoded>
			<wfw:commentRss>http://railstic.com/2008/08/updating-rubygems-to-12-manually/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Recursive methods with block in Ruby</title>
		<link>http://railstic.com/2008/08/recursive-methods-with-block/</link>
		<comments>http://railstic.com/2008/08/recursive-methods-with-block/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 10:46:17 +0000</pubDate>
		<dc:creator>İ. Emre Kutlu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://izzetemrekutlu.com/blog/?p=20</guid>
		<description><![CDATA[def comic&#40;cast&#41; cast.each do &#124;character&#124; unless character.is_a?&#40;Array&#41; yield&#40;character&#41; else comic&#40;character&#41; &#123;&#124;x&#124; yield x&#125; end end end This method takes an array as argument and checks each element if it is an Array. If the element is not an Array then the block is called. If the element is an Array then the same method is [...]]]></description>
			<content:encoded><![CDATA[<p></p>

<div class="wp_codebox"><table><tr id="p2016"><td class="code" id="p20code16"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> comic<span style="color:#006600; font-weight:bold;">&#40;</span>cast<span style="color:#006600; font-weight:bold;">&#41;</span>
   cast.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>character<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#9966CC; font-weight:bold;">unless</span> character.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#41;</span>
         <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span>character<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
	 comic<span style="color:#006600; font-weight:bold;">&#40;</span>character<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#9966CC; font-weight:bold;">yield</span> x<span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>
This method takes an array as argument and checks each element if it is an <em>Array</em>.<br />
If the element is not an <em>Array</em> then the block is called.<br />
If the element is an <em>Array</em> then the same method is called with that element as an argument and with the same block.<br />
<br />
Now let&#8217;s look how we can call this method.</p>

<div class="wp_codebox"><table><tr id="p2017"><td class="code" id="p20code17"><pre class="ruby" style="font-family:monospace;">names = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'lucky luke'</span>, <span style="color:#996600;">'jolly jumper'</span>, <span style="color:#996600;">'rin tin tin'</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'joe'</span>, <span style="color:#996600;">'william'</span>,<span style="color:#996600;">'jack'</span>, <span style="color:#996600;">'averell'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
comic<span style="color:#006600; font-weight:bold;">&#40;</span>names<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">puts</span> c<span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>
<strong>Output :</strong></p>

<div class="wp_codebox"><table><tr id="p2018"><td class="code" id="p20code18"><pre class="bash" style="font-family:monospace;">lucky luke
jolly jumper
rin tin tin
joe
william
jack
averell</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://railstic.com/2008/08/recursive-methods-with-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

