<?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: Other ways to wrap a method</title>
	<atom:link href="http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/</link>
	<description>Random Geek-Related Thoughts</description>
	<lastBuildDate>Wed, 08 Sep 2010 23:53:11 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Utilisation des modules Ruby à la place des fameux alias_method_chain</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-16302</link>
		<dc:creator>Utilisation des modules Ruby à la place des fameux alias_method_chain</dc:creator>
		<pubDate>Mon, 13 Apr 2009 07:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-16302</guid>
		<description>[...] sur un article intéressant sur le blog de Jan Wedekind s&#8217;inspirant lui même de celui de Yehuda Katz. Celui ci décrit une façon de redéfinir une méthode plus &#8220;Ruby Way&#8221; que [...]</description>
		<content:encoded><![CDATA[<p>[...] sur un article intéressant sur le blog de Jan Wedekind s&#8217;inspirant lui même de celui de Yehuda Katz. Celui ci décrit une façon de redéfinir une méthode plus &#8220;Ruby Way&#8221; que [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Konstantin Haase</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-16196</link>
		<dc:creator>Konstantin Haase</dc:creator>
		<pubDate>Sun, 22 Mar 2009 13:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-16196</guid>
		<description>I just wanted to let you now, that I wrote a script (in ruby!) that does something like &quot;the best of all worlds ( without  a caveat)&quot;:

http://github.com/rkh/chainable</description>
		<content:encoded><![CDATA[<p>I just wanted to let you now, that I wrote a script (in ruby!) that does something like &#8220;the best of all worlds ( without  a caveat)&#8221;:</p>
<p><a href="http://github.com/rkh/chainable" rel="nofollow">http://github.com/rkh/chainable</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Spurrier</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15639</link>
		<dc:creator>Greg Spurrier</dc:creator>
		<pubDate>Tue, 27 Jan 2009 19:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15639</guid>
		<description>I like the idea of explicitly declaring a method as chainable.

My question, though, is how to you test/spec the wrapped method?  With AMC, I usually stub or mock the aliased original method to make sure it is getting invoked as expected from within the wrapper.  How do you do that when you are invoking it via super?</description>
		<content:encoded><![CDATA[<p>I like the idea of explicitly declaring a method as chainable.</p>
<p>My question, though, is how to you test/spec the wrapped method?  With AMC, I usually stub or mock the aliased original method to make sure it is getting invoked as expected from within the wrapper.  How do you do that when you are invoking it via super?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel Horner</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15550</link>
		<dc:creator>Gabriel Horner</dc:creator>
		<pubDate>Tue, 20 Jan 2009 19:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15550</guid>
		<description>Nice writeup. I think there&#039;s a typo when you first introduced the chainable method. &#039;def chainable&#039; should be &#039;def bar&#039;. On a related note, I just released a gem to easily alias methods/classes when in irb: http://github.com/cldwalker/alias/tree/master</description>
		<content:encoded><![CDATA[<p>Nice writeup. I think there&#8217;s a typo when you first introduced the chainable method. &#8216;def chainable&#8217; should be &#8216;def bar&#8217;. On a related note, I just released a gem to easily alias methods/classes when in irb: <a href="http://github.com/cldwalker/alias/tree/master" rel="nofollow">http://github.com/cldwalker/alias/tree/master</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex P</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15546</link>
		<dc:creator>Alex P</dc:creator>
		<pubDate>Tue, 20 Jan 2009 15:26:54 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15546</guid>
		<description>maybe I am missing something, but why do you need to include module inside override
def override(&amp;blk)
    mod = Module.new do
      extend TrackAddedMethods
    end
    mod.class_eval(&amp;blk)
    __move_to_module(*mod.__added_methods)
    include mod
end

it looks like it is already included by __move_to_module... Am I missing something?</description>
		<content:encoded><![CDATA[<p>maybe I am missing something, but why do you need to include module inside override<br />
def override(&amp;blk)<br />
    mod = Module.new do<br />
      extend TrackAddedMethods<br />
    end<br />
    mod.class_eval(&amp;blk)<br />
    __move_to_module(*mod.__added_methods)<br />
    include mod<br />
end</p>
<p>it looks like it is already included by __move_to_module&#8230; Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antares Trader</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15527</link>
		<dc:creator>Antares Trader</dc:creator>
		<pubDate>Mon, 19 Jan 2009 01:13:45 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15527</guid>
		<description>@Ted Han:  Have a look at Extlib::Hook for general purpose before and after hooks.  As Yahuda pointed out in another post the library lacks conditionals filters, but so does AMC.  because hooks work on a per method basis there is really nothing to be done about filters, but I know conditional can be added.  The only question in my mind is how expensive they will be.</description>
		<content:encoded><![CDATA[<p>@Ted Han:  Have a look at Extlib::Hook for general purpose before and after hooks.  As Yahuda pointed out in another post the library lacks conditionals filters, but so does AMC.  because hooks work on a per method basis there is really nothing to be done about filters, but I know conditional can be added.  The only question in my mind is how expensive they will be.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ted Han</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15521</link>
		<dc:creator>Ted Han</dc:creator>
		<pubDate>Sun, 18 Jan 2009 17:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15521</guid>
		<description>Crazy stuff Yehuda!

So, i don&#039;t know the MRI internals well enough to judge whether this is a good idea from an implementational standpoint.  I&#039;ve got a comment and a question.

I&#039;ve always wanted more powerful hooks in Ruby.  I think it&#039;d be cool to have the ability (before or after) a class or a method is defined or added to an object, to be able to manipulate that method, object or the host/parent in which the object is defined.

This sort of looks like a step in that direction (although not general purpose yeh?).

Further to that, how do you access prior versions of a method?

(Yehuda answered this question for me elsewhere.  You&#039;ve still got access to the ancestor chain of methods via &#039;super&#039;, so if you wanted any of the intermediate definitions of a method, you can get at &#039;em, if you know the order in which they were added).</description>
		<content:encoded><![CDATA[<p>Crazy stuff Yehuda!</p>
<p>So, i don&#8217;t know the MRI internals well enough to judge whether this is a good idea from an implementational standpoint.  I&#8217;ve got a comment and a question.</p>
<p>I&#8217;ve always wanted more powerful hooks in Ruby.  I think it&#8217;d be cool to have the ability (before or after) a class or a method is defined or added to an object, to be able to manipulate that method, object or the host/parent in which the object is defined.</p>
<p>This sort of looks like a step in that direction (although not general purpose yeh?).</p>
<p>Further to that, how do you access prior versions of a method?</p>
<p>(Yehuda answered this question for me elsewhere.  You&#8217;ve still got access to the ancestor chain of methods via &#8216;super&#8217;, so if you wanted any of the intermediate definitions of a method, you can get at &#8216;em, if you know the order in which they were added).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yehuda Katz</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15520</link>
		<dc:creator>Yehuda Katz</dc:creator>
		<pubDate>Sun, 18 Jan 2009 17:11:24 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15520</guid>
		<description>@teamon this technique can easily work on jruby

@iain the issue I have with amc is that it&#039;s a very leaky abstraction. The goal here is to make an abstraction that is much less leaky so that the implementation doesn&#039;t *matter*. If you go look at the implementation of alias_method you&#039;ll see that it&#039;s quite complex, but you don&#039;t *have* to look at it because it works perfectly 100% of the time.</description>
		<content:encoded><![CDATA[<p>@teamon this technique can easily work on jruby</p>
<p>@iain the issue I have with amc is that it&#8217;s a very leaky abstraction. The goal here is to make an abstraction that is much less leaky so that the implementation doesn&#8217;t *matter*. If you go look at the implementation of alias_method you&#8217;ll see that it&#8217;s quite complex, but you don&#8217;t *have* to look at it because it works perfectly 100% of the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: iain</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15518</link>
		<dc:creator>iain</dc:creator>
		<pubDate>Sun, 18 Jan 2009 11:22:53 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15518</guid>
		<description>I do like alias_method_chain. If you know how it works, it is easy to find the methods it uses. If you see a method name =~ /\w_with_\w/ or /\w_without_\w/, you can recognize what has been done. It is very transparent imho. I don&#039;t like specifying your old method to be overridable, for the reason you mentioned. It sounds more natural for me to say to the overriding method that it&#039;s overriding something. But it might be because I&#039;m used to it. What about:

class Foo
  def bar
    1
  end
  override :bar do &#124;old_bar&#124;
    old_bar   1
  end
end

I have of course no idea about it&#039;s implementation. Unfortunately ruby 1.8 doesn&#039;t support blocks this way...</description>
		<content:encoded><![CDATA[<p>I do like alias_method_chain. If you know how it works, it is easy to find the methods it uses. If you see a method name =~ /\w_with_\w/ or /\w_without_\w/, you can recognize what has been done. It is very transparent imho. I don&#8217;t like specifying your old method to be overridable, for the reason you mentioned. It sounds more natural for me to say to the overriding method that it&#8217;s overriding something. But it might be because I&#8217;m used to it. What about:</p>
<p>class Foo<br />
  def bar<br />
    1<br />
  end<br />
  override :bar do |old_bar|<br />
    old_bar   1<br />
  end<br />
end</p>
<p>I have of course no idea about it&#8217;s implementation. Unfortunately ruby 1.8 doesn&#8217;t support blocks this way&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: teamon</title>
		<link>http://yehudakatz.com/2009/01/18/other-ways-to-wrap-a-method/comment-page-1/#comment-15516</link>
		<dc:creator>teamon</dc:creator>
		<pubDate>Sun, 18 Jan 2009 10:16:03 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=196#comment-15516</guid>
		<description>What about jruby?</description>
		<content:encoded><![CDATA[<p>What about jruby?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
