<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Metaprogramming in Ruby: It&#8217;s All About the Self</title>
	<atom:link href="http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/feed/" rel="self" type="application/rss+xml" />
	<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/</link>
	<description>Random Geek-Related Thoughts</description>
	<lastBuildDate>Tue, 16 Mar 2010 14:46:49 -0700</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: incognitus</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17736</link>
		<dc:creator>incognitus</dc:creator>
		<pubDate>Sun, 20 Dec 2009 20:36:20 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17736</guid>
		<description>s/Homo Sapien/Homo Sapiens/g; http://en.wikipedia.org/wiki/Homo_Sapiens</description>
		<content:encoded><![CDATA[<p>s/Homo Sapien/Homo Sapiens/g; <a href="http://en.wikipedia.org/wiki/Homo_Sapiens" rel="nofollow">http://en.wikipedia.org/wiki/Homo_Sapiens</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabe da Silveira</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17727</link>
		<dc:creator>Gabe da Silveira</dc:creator>
		<pubDate>Tue, 15 Dec 2009 22:29:24 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17727</guid>
		<description>@les The reason is simple.  The syntax &#039;bareword = :foo&#039; is ALWAYS local assignment.  It could conceivably do something fancy like lookup to see if a &#039;bareword=&#039; method exists, but that would be potentially even more confusing given potential method_missing? implementations.  As it is you just need to remember the one simple rule to use self for setters (and occasionally to avoid keyword conflicts).</description>
		<content:encoded><![CDATA[<p>@les The reason is simple.  The syntax &#8216;bareword = :foo&#8217; is ALWAYS local assignment.  It could conceivably do something fancy like lookup to see if a &#8216;bareword=&#8217; method exists, but that would be potentially even more confusing given potential method_missing? implementations.  As it is you just need to remember the one simple rule to use self for setters (and occasionally to avoid keyword conflicts).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les Nightingill</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17458</link>
		<dc:creator>Les Nightingill</dc:creator>
		<pubDate>Tue, 17 Nov 2009 14:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17458</guid>
		<description>Thanks, Yehuda
OK, that explains what is happening, but why? This same behaviour is not seen if I replace the setter methods with getter methods throughout.
In the case that Ruby is simply assigning to a local variable, wouldn&#039;t you have expected it to send the method to the (implicit) self receiver?</description>
		<content:encoded><![CDATA[<p>Thanks, Yehuda<br />
OK, that explains what is happening, but why? This same behaviour is not seen if I replace the setter methods with getter methods throughout.<br />
In the case that Ruby is simply assigning to a local variable, wouldn&#8217;t you have expected it to send the method to the (implicit) self receiver?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wycats</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17451</link>
		<dc:creator>wycats</dc:creator>
		<pubDate>Tue, 17 Nov 2009 06:26:46 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17451</guid>
		<description>@les what&#039;s happening there is that original_some_method=(attributes) is actually setting the local variable original_some_method.

Take a look at the ripper output:

&gt; pp Ripper::SexpBuilder.new(&quot;original_some_method=(attributes)&quot;).parse
[:program,
 [:stmts_add,
  [:stmts_new],
  [:assign,
   [:var_field, [:@ident, &quot;original_some_method&quot;, [1, 0]]],
   [:paren,
    [:stmts_add,
     [:stmts_new],
     [:var_ref, [:@ident, &quot;attributes&quot;, [1, 22]]]]]]]]

You can see that there&#039;s an &quot;assign&quot; to a :var_field (local variable).

&gt; pp Ripper::SexpBuilder.new(&quot;self.original_some_method=(attributes)&quot;).parse
[:program,
 [:stmts_add,
  [:stmts_new],
  [:assign,
   [:field,
    [:var_ref, [:@kw, &quot;self&quot;, [1, 0]]],
    :&quot;.&quot;,
    [:@ident, &quot;original_some_method&quot;, [1, 5]]],
   [:paren,
    [:stmts_add,
     [:stmts_new],
     [:var_ref, [:@ident, &quot;attributes&quot;, [1, 27]]]]]]]]

Here, there&#039;s an &quot;assign&quot; to self.original_some_method.</description>
		<content:encoded><![CDATA[<p>@les what&#8217;s happening there is that original_some_method=(attributes) is actually setting the local variable original_some_method.</p>
<p>Take a look at the ripper output:</p>
<p>> pp Ripper::SexpBuilder.new(&#8220;original_some_method=(attributes)&#8221;).parse<br />
[:program,<br />
 [:stmts_add,<br />
  [:stmts_new],<br />
  [:assign,<br />
   [:var_field, [:@ident, "original_some_method", [1, 0]]],<br />
   [:paren,<br />
    [:stmts_add,<br />
     [:stmts_new],<br />
     [:var_ref, [:@ident, "attributes", [1, 22]]]]]]]]</p>
<p>You can see that there&#8217;s an &#8220;assign&#8221; to a :var_field (local variable).</p>
<p>> pp Ripper::SexpBuilder.new(&#8220;self.original_some_method=(attributes)&#8221;).parse<br />
[:program,<br />
 [:stmts_add,<br />
  [:stmts_new],<br />
  [:assign,<br />
   [:field,<br />
    [:var_ref, [:@kw, "self", [1, 0]]],<br />
    :&#8221;.&#8221;,<br />
    [:@ident, "original_some_method", [1, 5]]],<br />
   [:paren,<br />
    [:stmts_add,<br />
     [:stmts_new],<br />
     [:var_ref, [:@ident, "attributes", [1, 27]]]]]]]]</p>
<p>Here, there&#8217;s an &#8220;assign&#8221; to self.original_some_method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les Nightingill</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17450</link>
		<dc:creator>Les Nightingill</dc:creator>
		<pubDate>Tue, 17 Nov 2009 05:56:08 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17450</guid>
		<description>Nice write-up, thanks, Yehuda.
I thought I understood it pretty well until I ran across the following. Why do you think the two calls to #original_some_method, one with and one without the explicit &quot;self&quot; receiver, behave differently?

class Someclass
  
  def some_method=(attributes)
    puts(&quot;in the original method with #{attributes}&quot;)
  end
  
  alias_method :original_some_method=, :some_method=

  def some_method=(attributes)
    puts(&quot;in the new method with #{attributes}&quot;)
    original_some_method=(attributes) # the original_some_method isn&#039;t called, fails silently
    puts(&quot;between calls to original_some_method&quot;)
    self.original_some_method=(attributes) # the original_some_method IS called, because of the explicit self receiver
  end
end

p = Someclass.new
p.some_method=(&quot;foo&quot;)

# Result is:
# in the new method with foo
# between calls to original_some_method
# in the original method with foo</description>
		<content:encoded><![CDATA[<p>Nice write-up, thanks, Yehuda.<br />
I thought I understood it pretty well until I ran across the following. Why do you think the two calls to #original_some_method, one with and one without the explicit &#8220;self&#8221; receiver, behave differently?</p>
<p>class Someclass</p>
<p>  def some_method=(attributes)<br />
    puts(&#8220;in the original method with #{attributes}&#8221;)<br />
  end</p>
<p>  alias_method :original_some_method=, :some_method=</p>
<p>  def some_method=(attributes)<br />
    puts(&#8220;in the new method with #{attributes}&#8221;)<br />
    original_some_method=(attributes) # the original_some_method isn&#8217;t called, fails silently<br />
    puts(&#8220;between calls to original_some_method&#8221;)<br />
    self.original_some_method=(attributes) # the original_some_method IS called, because of the explicit self receiver<br />
  end<br />
end</p>
<p>p = Someclass.new<br />
p.some_method=(&#8220;foo&#8221;)</p>
<p># Result is:<br />
# in the new method with foo<br />
# between calls to original_some_method<br />
# in the original method with foo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared Grippe</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17443</link>
		<dc:creator>Jared Grippe</dc:creator>
		<pubDate>Tue, 17 Nov 2009 00:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17443</guid>
		<description>Thanks for the knowledge and the inspiration http://jaredgrippe.com/post/246559026/javascript-like-ruby</description>
		<content:encoded><![CDATA[<p>Thanks for the knowledge and the inspiration <a href="http://jaredgrippe.com/post/246559026/javascript-like-ruby" rel="nofollow">http://jaredgrippe.com/post/246559026/javascript-like-ruby</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shih-gian Lee</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17438</link>
		<dc:creator>Shih-gian Lee</dc:creator>
		<pubDate>Mon, 16 Nov 2009 19:07:08 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17438</guid>
		<description>This is a nice write up and it is consistent with Dave Thomas&#039; screen casts on meta-programming. The additional information on instance_eval is interesting, though can be confusing sometime.</description>
		<content:encoded><![CDATA[<p>This is a nice write up and it is consistent with Dave Thomas&#8217; screen casts on meta-programming. The additional information on instance_eval is interesting, though can be confusing sometime.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich Collins</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17437</link>
		<dc:creator>Rich Collins</dc:creator>
		<pubDate>Mon, 16 Nov 2009 18:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17437</guid>
		<description>@wycats Right.  That is why they are unnecessary and only confuse developers.  I didn&#039;t see this until I happened to discover Io.  After learning Io I was using Ruby and had to (once again) consult Pickaxe so I could remember the details of Ruby&#039;s complicated inheritance / lookup model.  Staring at the page in the context of having recently learned a simpler way, it was easy to see that classes, metaclasses, modules, class variables instance variables (and even blocks) aren&#039;t needed.  All you really need are objects that inherit from each other, slots and messages.</description>
		<content:encoded><![CDATA[<p>@wycats Right.  That is why they are unnecessary and only confuse developers.  I didn&#8217;t see this until I happened to discover Io.  After learning Io I was using Ruby and had to (once again) consult Pickaxe so I could remember the details of Ruby&#8217;s complicated inheritance / lookup model.  Staring at the page in the context of having recently learned a simpler way, it was easy to see that classes, metaclasses, modules, class variables instance variables (and even blocks) aren&#8217;t needed.  All you really need are objects that inherit from each other, slots and messages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: glie</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17436</link>
		<dc:creator>glie</dc:creator>
		<pubDate>Mon, 16 Nov 2009 16:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17436</guid>
		<description>Great article, thanks.

I initially got a handle on ruby&#039;s metaclasses from Brian Marick&#039;s partially completed book (chp 3): 

http://www.visibleworkings.com/little-ruby/

A great resource</description>
		<content:encoded><![CDATA[<p>Great article, thanks.</p>
<p>I initially got a handle on ruby&#8217;s metaclasses from Brian Marick&#8217;s partially completed book (chp 3): </p>
<p><a href="http://www.visibleworkings.com/little-ruby/" rel="nofollow">http://www.visibleworkings.com/little-ruby/</a></p>
<p>A great resource</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wycats</title>
		<link>http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/comment-page-1/#comment-17420</link>
		<dc:creator>wycats</dc:creator>
		<pubDate>Mon, 16 Nov 2009 02:50:43 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=367#comment-17420</guid>
		<description>@yugui @banisterfiend I have updated my post to reflect that instance_eval has different behavior than the other constructs, breaking up the self into &quot;method defined on&quot; and &quot;methods resolved on&quot;. Thanks for the correction!</description>
		<content:encoded><![CDATA[<p>@yugui @banisterfiend I have updated my post to reflect that instance_eval has different behavior than the other constructs, breaking up the self into &#8220;method defined on&#8221; and &#8220;methods resolved on&#8221;. Thanks for the correction!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
