<?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: Better Ruby Idioms</title>
	<atom:link href="http://yehudakatz.com/2009/11/12/better-ruby-idioms/feed/" rel="self" type="application/rss+xml" />
	<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/</link>
	<description>Random Geek-Related Thoughts</description>
	<lastBuildDate>Sat, 20 Apr 2013 07:23:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Wojciech Kruszewski</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-22191</link>
		<dc:creator>Wojciech Kruszewski</dc:creator>
		<pubDate>Thu, 20 Jan 2011 09:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-22191</guid>
		<description><![CDATA[Yehuda, you *can&#039;t* do it like this. acts_as_something with ClassMethods and InstanceMethods and abstraction layer is a well established programming patter. It&#039;s enterprise, you see :P]]></description>
		<content:encoded><![CDATA[<p>Yehuda, you *can&#8217;t* do it like this. acts_as_something with ClassMethods and InstanceMethods and abstraction layer is a well established programming patter. It&#8217;s enterprise, you see :P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-21739</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Wed, 17 Nov 2010 01:40:02 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-21739</guid>
		<description><![CDATA[What defining about an include and extend method?

class Class
  def include_and_extend(the_module)
    include the_module
    extend the_module::ClassMethods
  end
end

class Article &lt; ActiveRecord::Base
  include_and_extend Yaffle
end

http://glosoli.blogspot.com/2010/11/includeandextend-method-for-ruby.html]]></description>
		<content:encoded><![CDATA[<p>What defining about an include and extend method?</p>
<p>class Class<br />
  def include_and_extend(the_module)<br />
    include the_module<br />
    extend the_module::ClassMethods<br />
  end<br />
end</p>
<p>class Article &lt; ActiveRecord::Base<br />
  include_and_extend Yaffle<br />
end</p>
<p><a href="http://glosoli.blogspot.com/2010/11/includeandextend-method-for-ruby.html" rel="nofollow">http://glosoli.blogspot.com/2010/11/includeandextend-method-for-ruby.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thoran</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-18979</link>
		<dc:creator>thoran</dc:creator>
		<pubDate>Wed, 05 May 2010 08:19:22 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-18979</guid>
		<description><![CDATA[@wycats: Rather than &quot;overriding include&quot; I might prefer to call it sidestepping or bypassing extend().  In fact I don&#039;t think I like the term include() at all.  Is instance_extend() better?  Either that or include is kept and the compliment becomes class_include.  Generally, though, the usefulness of having everything modular, such that doing the mixin by loading everything dynamically rather than by simply opening a class, is dependent upon the reversability of mixins in Ruby.  If it were possible to drop a module in and rip it back out of a class (or another module) again with equal ease, then sure, don&#039;t go opening classes.  However, since Module#uninclude/exclude and Module#unextend/retract (And, assuming instance_extend, then we should have #instance_unextend/instance_retract, or alternately we might have Module#class_uninclude/class_exclude.) don&#039;t exist (I ought to know, since I&#039;m writing it in POR (Plain Old Ruby) right now and hence how I got here for the second time when looking for a pre-existing solution.), and since there doesn&#039;t exist a way to easily remove functionality on a per module basis from the ancestors chain, there is insufficient reason to have everything modular and to load it dynamically at this time.  The trick to making Module#exclude or Module#retract work properly is to ensure that by removing one module that the functionality provided by another included/extending module isn&#039;t becoming some portion of useless because of a dependency on the one removed.  Short of that, it is possible to do this with a little jiggery-pokery.  I&#039;m nearly there by way of introspecting on the module and trashing all the methods on the target class or module...  Apart from a dependency issue amongst modules, there remains a problem with it remaining in the ancestors chain though, since a reference to the included module remains doing it this way.  The alternative to actually banging on the target class or module, and a feature of Ruby I have wanted for about half a decade now is to be able to create context-specific instances of a class where the desired additional (or reduced functionality), such that the functionality exists either actually within or appears to reside within the class of concern, but then outside the context returns to &#039;normal&#039;.  Something like the eye-popping lambda-lambda-lambda stuff Raganwald was working on a couple of years ago suffices, but what a pain to have to go to all that trouble, when it isn&#039;t unreasonably included into a language with the sort of dynamism which we expect of Ruby.  I was pleased to see that _why also took this approach with Poison.  I&#039;m working on something pretty horrible in Ruby to accomplish this as well just now...  If it isn&#039;t worse than ghastly I&#039;ll eventually get it onto github.  @Peter: The syntax I have at the moment is very much like what you suggest.  In your case it would be Post.uses(ActsAsPlugin, :configuration =&gt; true) do; stuff; end.  In that way Post could optionally act as if it had a plugin.  I&#039;m not presently worried about the machine efficiency of doing this because it should not be my concern at this level as to how quicly this operation works.  It should be the internals of the language which worries about realising that a particular module has or has not been included already and to cache it somehow.]]></description>
		<content:encoded><![CDATA[<p>@wycats: Rather than &#8220;overriding include&#8221; I might prefer to call it sidestepping or bypassing extend().  In fact I don&#8217;t think I like the term include() at all.  Is instance_extend() better?  Either that or include is kept and the compliment becomes class_include.  Generally, though, the usefulness of having everything modular, such that doing the mixin by loading everything dynamically rather than by simply opening a class, is dependent upon the reversability of mixins in Ruby.  If it were possible to drop a module in and rip it back out of a class (or another module) again with equal ease, then sure, don&#8217;t go opening classes.  However, since Module#uninclude/exclude and Module#unextend/retract (And, assuming instance_extend, then we should have #instance_unextend/instance_retract, or alternately we might have Module#class_uninclude/class_exclude.) don&#8217;t exist (I ought to know, since I&#8217;m writing it in POR (Plain Old Ruby) right now and hence how I got here for the second time when looking for a pre-existing solution.), and since there doesn&#8217;t exist a way to easily remove functionality on a per module basis from the ancestors chain, there is insufficient reason to have everything modular and to load it dynamically at this time.  The trick to making Module#exclude or Module#retract work properly is to ensure that by removing one module that the functionality provided by another included/extending module isn&#8217;t becoming some portion of useless because of a dependency on the one removed.  Short of that, it is possible to do this with a little jiggery-pokery.  I&#8217;m nearly there by way of introspecting on the module and trashing all the methods on the target class or module&#8230;  Apart from a dependency issue amongst modules, there remains a problem with it remaining in the ancestors chain though, since a reference to the included module remains doing it this way.  The alternative to actually banging on the target class or module, and a feature of Ruby I have wanted for about half a decade now is to be able to create context-specific instances of a class where the desired additional (or reduced functionality), such that the functionality exists either actually within or appears to reside within the class of concern, but then outside the context returns to &#8216;normal&#8217;.  Something like the eye-popping lambda-lambda-lambda stuff Raganwald was working on a couple of years ago suffices, but what a pain to have to go to all that trouble, when it isn&#8217;t unreasonably included into a language with the sort of dynamism which we expect of Ruby.  I was pleased to see that _why also took this approach with Poison.  I&#8217;m working on something pretty horrible in Ruby to accomplish this as well just now&#8230;  If it isn&#8217;t worse than ghastly I&#8217;ll eventually get it onto github.  @Peter: The syntax I have at the moment is very much like what you suggest.  In your case it would be Post.uses(ActsAsPlugin, :configuration =&gt; true) do; stuff; end.  In that way Post could optionally act as if it had a plugin.  I&#8217;m not presently worried about the machine efficiency of doing this because it should not be my concern at this level as to how quicly this operation works.  It should be the internals of the language which worries about realising that a particular module has or has not been included already and to cache it somehow.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Priit</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-18532</link>
		<dc:creator>Priit</dc:creator>
		<pubDate>Fri, 05 Mar 2010 20:10:51 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-18532</guid>
		<description><![CDATA[@wycats: I think one good overview about AR anti-&quot;super&quot;: http://stackoverflow.com/questions/373731/override-activerecord-attribute-methods and the same thing goes for initialize method as we know. Anyhow, it&#039;s very welcome to see rails 3 become better ruby citizens with optional defaults. Keep up good work about promoting cleaner ruby style.]]></description>
		<content:encoded><![CDATA[<p>@wycats: I think one good overview about AR anti-&#8221;super&#8221;: <a href="http://stackoverflow.com/questions/373731/override-activerecord-attribute-methods" rel="nofollow">http://stackoverflow.com/questions/373731/override-activerecord-attribute-methods</a> and the same thing goes for initialize method as we know. Anyhow, it&#8217;s very welcome to see rails 3 become better ruby citizens with optional defaults. Keep up good work about promoting cleaner ruby style.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ste</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-18018</link>
		<dc:creator>ste</dc:creator>
		<pubDate>Tue, 19 Jan 2010 16:55:20 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-18018</guid>
		<description><![CDATA[A bit late, but here&#039;s my take:

http://gist.github.com/281080

If someone is still reading this, can you tell me if it makes sense? :-)]]></description>
		<content:encoded><![CDATA[<p>A bit late, but here&#8217;s my take:</p>
<p><a href="http://gist.github.com/281080" rel="nofollow">http://gist.github.com/281080</a></p>
<p>If someone is still reading this, can you tell me if it makes sense? :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Durity</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-17699</link>
		<dc:creator>Adam Durity</dc:creator>
		<pubDate>Sat, 12 Dec 2009 01:50:52 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-17699</guid>
		<description><![CDATA[I must agree whole heartedly.  When I first started with Rails, though I had worked with Ruby prior, I didn&#039;t have a grasp on some concepts.  I remember slugging through AuthLogic code trying to interpret it.  While Ben Johnson did a great job on the library, it is wrought with the kind of patterns that you describe above, making it tough to review.

Hopefully this clears it up for some newer folks.]]></description>
		<content:encoded><![CDATA[<p>I must agree whole heartedly.  When I first started with Rails, though I had worked with Ruby prior, I didn&#8217;t have a grasp on some concepts.  I remember slugging through AuthLogic code trying to interpret it.  While Ben Johnson did a great job on the library, it is wrought with the kind of patterns that you describe above, making it tough to review.</p>
<p>Hopefully this clears it up for some newer folks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marek K</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-17530</link>
		<dc:creator>Marek K</dc:creator>
		<pubDate>Mon, 23 Nov 2009 22:44:01 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-17530</guid>
		<description><![CDATA[Nice post, it can clear up this include/extend magic indeed. 

But what bothers me is why this overkill pattern with additional module layers came up in the first place. I mean - are there some really good reasons to use the classic act_as_overkill way?]]></description>
		<content:encoded><![CDATA[<p>Nice post, it can clear up this include/extend magic indeed. </p>
<p>But what bothers me is why this overkill pattern with additional module layers came up in the first place. I mean &#8211; are there some really good reasons to use the classic act_as_overkill way?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Browne</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-17493</link>
		<dc:creator>Peter Browne</dc:creator>
		<pubDate>Fri, 20 Nov 2009 21:46:27 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-17493</guid>
		<description><![CDATA[Speaking of Rails Plugin Idioms...There should be a better, more consistent approach to including plugins.

class Post
  include ActsAsPlugin 
end

class Post
  acts_as_plugin :configuration =&gt; true
end

Compare the 2 approaches: #1 is much less &quot;magical&quot; and also has the advantage of not including the acts_as_plugin method into every ActiveRecord class. But obviously, #2 allows for configuration options.

Wouldn&#039;t it be cool if there was a specific API for including plugins that would have the advantages of both approaches. Something like:

class Post
  use ActsAsPlugin, :configuration =&gt; true
end]]></description>
		<content:encoded><![CDATA[<p>Speaking of Rails Plugin Idioms&#8230;There should be a better, more consistent approach to including plugins.</p>
<p>class Post<br />
  include ActsAsPlugin<br />
end</p>
<p>class Post<br />
  acts_as_plugin :configuration =&gt; true<br />
end</p>
<p>Compare the 2 approaches: #1 is much less &#8220;magical&#8221; and also has the advantage of not including the acts_as_plugin method into every ActiveRecord class. But obviously, #2 allows for configuration options.</p>
<p>Wouldn&#8217;t it be cool if there was a specific API for including plugins that would have the advantages of both approaches. Something like:</p>
<p>class Post<br />
  use ActsAsPlugin, :configuration =&gt; true<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eloy Duran</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-17393</link>
		<dc:creator>Eloy Duran</dc:creator>
		<pubDate>Sat, 14 Nov 2009 14:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-17393</guid>
		<description><![CDATA[Amen]]></description>
		<content:encoded><![CDATA[<p>Amen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Grant</title>
		<link>http://yehudakatz.com/2009/11/12/better-ruby-idioms/comment-page-1/#comment-17392</link>
		<dc:creator>Adam Grant</dc:creator>
		<pubDate>Sat, 14 Nov 2009 00:25:11 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=365#comment-17392</guid>
		<description><![CDATA[Holy Cow!

Balls, my friend: clear-thinking BALLS is what you have.

Yeah, I REALLY had a hard time learning how to open classes/extend stuff for the first 2 years of doing Rails work because of this crap. Glad to see someone is as fed up with it as I am!

Hallelujah!]]></description>
		<content:encoded><![CDATA[<p>Holy Cow!</p>
<p>Balls, my friend: clear-thinking BALLS is what you have.</p>
<p>Yeah, I REALLY had a hard time learning how to open classes/extend stuff for the first 2 years of doing Rails work because of this crap. Glad to see someone is as fed up with it as I am!</p>
<p>Hallelujah!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
