<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Class Methods Part II - Annotations</title>
	<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/</link>
	<description>Ruby and otherwise by Patrick Farley</description>
	<pubDate>Sat, 13 Mar 2010 19:24:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: pfarley</title>
		<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-151</link>
		<dc:creator>pfarley</dc:creator>
		<pubDate>Mon, 12 Nov 2007 22:57:25 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-151</guid>
		<description>Hi Johnny,

Took a couple weeks off.  Thanks for the nice example.</description>
		<content:encoded><![CDATA[<p>Hi Johnny,</p>
<p>Took a couple weeks off.  Thanks for the nice example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johnny P</title>
		<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-148</link>
		<dc:creator>Johnny P</dc:creator>
		<pubDate>Wed, 07 Nov 2007 19:00:17 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-148</guid>
		<description>Well I found an answer to my own comment.
&#62;&#62; module E
&#62;&#62;   def accept_only(sym, &#38;body)
&#62;&#62;     define_method(sym) { &#124;*args&#124; puts args.inspect; body.call(*args) }
&#62;&#62;   end
&#62;&#62; end
=&#62; nil
&#62;&#62; class TestSomething
&#62;&#62;   extend E
&#62;&#62;   accept_only :setup_something do &#124;x&#124;
?&#62;     puts x + 2
&#62;&#62;   end
&#62;&#62; end
=&#62; #
&#62;&#62; t = TestSomething.new
=&#62; #
&#62;&#62; TestSomething.instance_methods(false).inspect
=&#62; "[\"setup_something\"]"
&#62;&#62; t.setup_something(1)
[1]
3
=&#62; nil</description>
		<content:encoded><![CDATA[<p>Well I found an answer to my own comment.<br />
&gt;&gt; module E<br />
&gt;&gt;   def accept_only(sym, &amp;body)<br />
&gt;&gt;     define_method(sym) { |*args| puts args.inspect; body.call(*args) }<br />
&gt;&gt;   end<br />
&gt;&gt; end<br />
=&gt; nil<br />
&gt;&gt; class TestSomething<br />
&gt;&gt;   extend E<br />
&gt;&gt;   accept_only :setup_something do |x|<br />
?&gt;     puts x + 2<br />
&gt;&gt;   end<br />
&gt;&gt; end<br />
=&gt; #<br />
&gt;&gt; t = TestSomething.new<br />
=&gt; #<br />
&gt;&gt; TestSomething.instance_methods(false).inspect<br />
=&gt; &#8220;[\&#8221;setup_something\&#8221;]&#8221;<br />
&gt;&gt; t.setup_something(1)<br />
[1]<br />
3<br />
=&gt; nil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johnny P</title>
		<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-140</link>
		<dc:creator>Johnny P</dc:creator>
		<pubDate>Tue, 30 Oct 2007 17:16:04 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-140</guid>
		<description>Patrick, great blog entry, thanks.  Just wondering after reading how the "Annotated Method Declaration" has access to the parameters passed?  You mentiion this as a distinguishing point, but don't actually show it. 

I cannot see how "acceptance_only :test_some_complex_calculation do" has any parameters to the new method test_some_complex_calculations, and I am not sure how it could.  The only thing I came up with was something heading toward simplexity and that is to actually define two methods.  The first would accept *args and then do whatever with them and then call the "acceptance_only" method.  Is there another way?

Thanks</description>
		<content:encoded><![CDATA[<p>Patrick, great blog entry, thanks.  Just wondering after reading how the &#8220;Annotated Method Declaration&#8221; has access to the parameters passed?  You mentiion this as a distinguishing point, but don&#8217;t actually show it. </p>
<p>I cannot see how &#8220;acceptance_only :test_some_complex_calculation do&#8221; has any parameters to the new method test_some_complex_calculations, and I am not sure how it could.  The only thing I came up with was something heading toward simplexity and that is to actually define two methods.  The first would accept *args and then do whatever with them and then call the &#8220;acceptance_only&#8221; method.  Is there another way?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pfarley</title>
		<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-137</link>
		<dc:creator>pfarley</dc:creator>
		<pubDate>Tue, 30 Oct 2007 03:54:01 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-137</guid>
		<description>Hi Daniel,

Thanks again for your comment.  If I were eliminating things left and right I might do something like below, but my tolerance for this sort of thing is pretty high as long as the methods are short and the source is in a reasonable place...

def self.exclude(platform_expression)
  @excluded_test = platform_match? platform_expression
end

def self.platform_match?(platform_expression)
  !platform_expression.find { &#124;key, value&#124; const_from_sym(key) &#038;&#038; const_from_sym(value) }.nil?
end

def self.const_from_sym(sym)
  Kernel.const_get(sym.to_s.upcase)
end

exclude :windows =&gt; :jruby
def test_something_jruby_doesnt_support_on_windows

end</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>Thanks again for your comment.  If I were eliminating things left and right I might do something like below, but my tolerance for this sort of thing is pretty high as long as the methods are short and the source is in a reasonable place&#8230;</p>
<p>def self.exclude(platform_expression)<br />
  @excluded_test = platform_match? platform_expression<br />
end</p>
<p>def self.platform_match?(platform_expression)<br />
  !platform_expression.find { |key, value| const_from_sym(key) &#038;&#038; const_from_sym(value) }.nil?<br />
end</p>
<p>def self.const_from_sym(sym)<br />
  Kernel.const_get(sym.to_s.upcase)<br />
end</p>
<p>exclude :windows => :jruby<br />
def test_something_jruby_doesnt_support_on_windows</p>
<p>end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Berger</title>
		<link>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-135</link>
		<dc:creator>Daniel Berger</dc:creator>
		<pubDate>Mon, 29 Oct 2007 21:48:06 +0000</pubDate>
		<guid>http://www.klankboomklang.com/2007/10/26/class-methods-part-ii-annotations/#comment-135</guid>
		<description>Oh, heck, maybe I should have used annotations for my personal Ruby test suite. Right now I'm just doing:

if WINDOWS
   def test_something
      ...
   end
end

Annotations would look better for the simple case. But, then I have times where I do stuff like:

if WINDOWS &#38;&#38; !JRUBY
   def test_someting_jruby_doesn't_support_on_windows
      ...
   end
end

And that's just one of several combinations. I don't know that there's a generic way to handle that. At least, not one that's less ugly.

Thanks again for a nice article, btw.

Dan</description>
		<content:encoded><![CDATA[<p>Oh, heck, maybe I should have used annotations for my personal Ruby test suite. Right now I&#8217;m just doing:</p>
<p>if WINDOWS<br />
   def test_something<br />
      &#8230;<br />
   end<br />
end</p>
<p>Annotations would look better for the simple case. But, then I have times where I do stuff like:</p>
<p>if WINDOWS &amp;&amp; !JRUBY<br />
   def test_someting_jruby_doesn&#8217;t_support_on_windows<br />
      &#8230;<br />
   end<br />
end</p>
<p>And that&#8217;s just one of several combinations. I don&#8217;t know that there&#8217;s a generic way to handle that. At least, not one that&#8217;s less ugly.</p>
<p>Thanks again for a nice article, btw.</p>
<p>Dan</p>
]]></content:encoded>
	</item>
</channel>
</rss>
