<?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>Vidul Nikolaev Petrov &#187; OOP</title>
	<atom:link href="http://www.vidul.com/category/oop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vidul.com</link>
	<description>my web space</description>
	<lastBuildDate>Fri, 09 Apr 2010 21:01:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>def and undef a method</title>
		<link>http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/</link>
		<comments>http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 05:50:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[method]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
def my_method; end # define a method
undef my_method    # remove a method

The core manual





		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Seed this on Newsvine
		





]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> my_method; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># define a method</span>
<span style="color:#9966CC; font-weight:bold;">undef</span> my_method    <span style="color:#008000; font-style:italic;"># remove a method</span></pre></div></div>

<p><a href="http://www.ruby-doc.org/core/classes/Module.html#M000394">The core manual</a></p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;Title=def+and+undef+a+method" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;title=def+and+undef+a+method" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;title=def+and+undef+a+method" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;title=def+and+undef+a+method" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;title=def+and+undef+a+method" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=def+and+undef+a+method+-+http://b2l.me/bmz7b+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/&amp;h=def+and+undef+a+method" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/07/25/definde-and-undefine-a-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple class&#8217;s variable accessor</title>
		<link>http://www.vidul.com/2008/07/19/simple-class-variables-acessor/</link>
		<comments>http://www.vidul.com/2008/07/19/simple-class-variables-acessor/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 05:13:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
class Class
  def attr&#40;arg&#41;
    arg = arg.to_s
    if self.class_variables.include?&#40;arg&#41;
      class_eval %&#40;def self.#{arg.sub(/^\@\@/, '')}; #{arg}; end)
    else
      raise ArgumentError, &#34;No such class attribute&#34;, caller
    end
  end
end
&#160;
class Test
  @@class_var = &#34;class variable [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> attr<span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span>
    arg = arg.<span style="color:#9900CC;">to_s</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">class_variables</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span>
      class_eval <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#008000; font-style:italic;">#{arg.sub(/^\@\@/, '')}; #{arg}; end)</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;No such class attribute&quot;</span>, <span style="color:#CC0066; font-weight:bold;">caller</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>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Test</span>
  @@class_var = <span style="color:#996600;">&quot;class variable value&quot;</span>
&nbsp;
  attr :@@class_var
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">Test</span>.<span style="color:#9900CC;">class_var</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;class variable value&quot;</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;Title=Simple+class%27s+variable+accessor" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;title=Simple+class%27s+variable+accessor" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;title=Simple+class%27s+variable+accessor" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;title=Simple+class%27s+variable+accessor" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;title=Simple+class%27s+variable+accessor" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Simple+class%27s+variable+accessor+-+http://b2l.me/bm25t+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/07/19/simple-class-variables-acessor/&amp;h=Simple+class%27s+variable+accessor" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/07/19/simple-class-variables-acessor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting an indication of the number of arguments accepted by a method</title>
		<link>http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/</link>
		<comments>http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 09:57:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
class Object
  def arguments?&#40;*methods&#41;
    methods.each do &#124;method&#124;
      begin
        rval = self.method&#40;method&#41;.arity
        if rval &#62; 0
          puts &#34;'#{method}' takes fixed (#{rval}) number of argument&#34;
 [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Object</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> arguments?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>methods<span style="color:#006600; font-weight:bold;">&#41;</span>
    methods.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>method<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        rval = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">method</span><span style="color:#006600; font-weight:bold;">&#40;</span>method<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">arity</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> rval <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">0</span>
          <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;'#{method}' takes fixed (#{rval}) number of argument&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">elsif</span> rval <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">0</span>
          <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;'#{method}' takes variable number of arguments&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">elsif</span> rval == <span style="color:#006666;">0</span>
          <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;'#{method}' takes no arguments&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span>
       <span style="color:#CC0066; font-weight:bold;">puts</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>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">arguments</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:size</span>, <span style="color:#ff3333; font-weight:bold;">:to_i</span>, <span style="color:#ff3333; font-weight:bold;">:scan</span>, <span style="color:#ff3333; font-weight:bold;">:flatten</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p><a href="http://www.ruby-doc.org/core/classes/Method.html#M000446">www.ruby-doc.org arity</a></pre>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;Title=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;title=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;title=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;title=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;title=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method+-+http://b2l.me/bnexg+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/&amp;h=Getting+an+indication+of+the+number+of+arguments+accepted+by+a+method" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/06/16/getting-number-of-arguments-accepted-by-a-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert an array to a hash</title>
		<link>http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/</link>
		<comments>http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/#comments</comments>
		<pubDate>Sun, 04 May 2008 22:56:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
class Array
  def to_h
    arr = self.dup
    if arr.size % 2 == 0
        Hash&#91;*arr&#93;
    else
        Hash&#91;*arr &#60; &#60; nil&#93;
    end
  end
end







		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">Array</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> to_h
    arr = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">dup</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> arr.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">2</span> == <span style="color:#006666;">0</span>
        <span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>arr<span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>arr <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#93;</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></div></div>

</pre>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;Title=Convert+an+array+to+a+hash" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;title=Convert+an+array+to+a+hash" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;title=Convert+an+array+to+a+hash" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;title=Convert+an+array+to+a+hash" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;title=Convert+an+array+to+a+hash" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Convert+an+array+to+a+hash+-+http://b2l.me/bmxvp+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/&amp;h=Convert+an+array+to+a+hash" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/05/04/convert-an-array-to-a-hash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically Define Methods</title>
		<link>http://www.vidul.com/2008/01/11/dynamically-define-methods/</link>
		<comments>http://www.vidul.com/2008/01/11/dynamically-define-methods/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 07:21:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[OOP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[method]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[Perl

package MyClass;
package main;
&#160;
*MyClass::from_my_class = sub &#123;
   print &#34;defined in &#34;, __PACKAGE__, &#34;\n&#34;
&#125;;
&#160;
MyClass::from_my_class&#40;&#41;;

Ruby

class String
  def self.from_string
    print &#34;defined in &#34; + self.name + $/
  end
end
&#160;
String::from_string
String. from_string






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Seed this on [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Perl</strong></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:arial,verdana,monospace;"><span style="color: #000066;">package</span> MyClass<span style="color: #339933;">;</span>
<span style="color: #000066;">package</span> main<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">*MyClass</span><span style="color: #339933;">::</span><span style="color: #006600;">from_my_class</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;defined in &quot;</span><span style="color: #339933;">,</span> __PACKAGE__<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
MyClass<span style="color: #339933;">::</span><span style="color: #006600;">from_my_class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Ruby</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_string</span>
    <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;defined in &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">+</span> $<span style="color:#006600; font-weight:bold;">/</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">String</span>::from_string
<span style="color:#CC0066; font-weight:bold;">String</span>. <span style="color:#9900CC;">from_string</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;Title=Dynamically+Define+Methods" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;title=Dynamically+Define+Methods" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;title=Dynamically+Define+Methods" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;title=Dynamically+Define+Methods" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;title=Dynamically+Define+Methods" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/01/11/dynamically-define-methods/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Dynamically+Define+Methods+-+http://b2l.me/bmxyk+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/01/11/dynamically-define-methods/&amp;h=Dynamically+Define+Methods" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/01/11/dynamically-define-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
