<?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: bool_attr_accessor for convenient question marks</title>
	<atom:link href="http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/</link>
	<description>Web Freshness</description>
	<lastBuildDate>Mon, 05 Jul 2010 23:44:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Berger</title>
		<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/comment-page-1/#comment-51</link>
		<dc:creator>Daniel Berger</dc:creator>
		<pubDate>Sun, 11 May 2008 04:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/#comment-51</guid>
		<description>You can blame James Britt for personally shooting down the proposal to have &quot;attr_accessor :recondite?&quot; fail to DWIM, so you have to write it out long hand.

Piers, you must be effing kidding me.

Dan</description>
		<content:encoded><![CDATA[<p>You can blame James Britt for personally shooting down the proposal to have &#8220;attr_accessor :recondite?&#8221; fail to DWIM, so you have to write it out long hand.</p>
<p>Piers, you must be effing kidding me.</p>
<p>Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: duncanbeevers</title>
		<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/comment-page-1/#comment-34</link>
		<dc:creator>duncanbeevers</dc:creator>
		<pubDate>Tue, 12 Feb 2008 03:59:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/#comment-34</guid>
		<description>Boolean accessors certainly aren&#039;t something you need every day, and using descriptive setters like that isn&#039;t a bad idea.

The reason I created these was for simple dirtiness checking on an attribute.

&lt;code lang=&quot;ruby&quot;&gt;
class SwitchBox &lt; ActiveRecord::Base
  bool_attr_accessor :button_pressed
  after_save :reset_buttons

  def press_button_one
    self.button_pressed = true
    # Do button one things
  end

  def press_button_two
    self.button_pressed = true
    # Do button two things
  end

  def reset_buttons
    if button_pressed?
      # Do cleanup things
      self.button_pressed = false
    end
  end
end
&lt;/code&gt;

Strictly for convenience.</description>
		<content:encoded><![CDATA[<p>Boolean accessors certainly aren&#8217;t something you need every day, and using descriptive setters like that isn&#8217;t a bad idea.</p>
<p>The reason I created these was for simple dirtiness checking on an attribute.</p>
<p><pre class="ruby"><span class="kw1">class</span> SwitchBox <span class="sy0">&lt;</span> <span class="re2">ActiveRecord::Base</span>
  bool_attr_accessor <span class="re3">:button_pressed</span>
  after_save <span class="re3">:reset_buttons</span>
&nbsp;
  <span class="kw1">def</span> press_button_one
    <span class="kw2">self</span>.<span class="me1">button_pressed</span> = <span class="kw2">true</span>
    <span class="co1"># Do button one things</span>
  <span class="kw1">end</span>
&nbsp;
  <span class="kw1">def</span> press_button_two
    <span class="kw2">self</span>.<span class="me1">button_pressed</span> = <span class="kw2">true</span>
    <span class="co1"># Do button two things</span>
  <span class="kw1">end</span>
&nbsp;
  <span class="kw1">def</span> reset_buttons
    <span class="kw1">if</span> button_pressed?
      <span class="co1"># Do cleanup things</span>
      <span class="kw2">self</span>.<span class="me1">button_pressed</span> = <span class="kw2">false</span>
    <span class="kw1">end</span>
  <span class="kw1">end</span>
<span class="kw1">end</span></pre></p>
<p>Strictly for convenience.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Piers Cawley</title>
		<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/comment-page-1/#comment-33</link>
		<dc:creator>Piers Cawley</dc:creator>
		<pubDate>Mon, 11 Feb 2008 16:20:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/#comment-33</guid>
		<description>Hmm... note to self: Check the preview!</description>
		<content:encoded><![CDATA[<p>Hmm&#8230; note to self: Check the preview!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Piers Cawley</title>
		<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/comment-page-1/#comment-32</link>
		<dc:creator>Piers Cawley</dc:creator>
		<pubDate>Mon, 11 Feb 2008 12:13:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/#comment-32</guid>
		<description>Assuming the attribute is supposed to be purely boolean, wouldn&#039;t you be better served by adding &lt;code lang=&quot;ruby&quot;&gt;:recondite?&lt;/code&gt;, &lt;code lang=&quot;ruby&quot;&gt;:set_recondite&lt;/code&gt;, &lt;code lang=&quot;ruby&quot;&gt;unset_recondite&lt;/code&gt; and, possibly, &lt;code lang=&quot;ruby&quot;&gt;toggle_recondite&lt;/code&gt;.

I tend to think of boolean accessors as code smells though...</description>
		<content:encoded><![CDATA[<p>Assuming the attribute is supposed to be purely boolean, wouldn&#8217;t you be better served by adding <pre class="ruby"><span class="re3">:recondite</span>?</pre>, <pre class="ruby"><span class="re3">:set_recondite</span></pre>, <pre class="ruby">unset_recondite</pre> and, possibly, <pre class="ruby">toggle_recondite</pre>.</p>
<p>I tend to think of boolean accessors as code smells though&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rick</title>
		<link>http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/comment-page-1/#comment-31</link>
		<dc:creator>rick</dc:creator>
		<pubDate>Fri, 08 Feb 2008 07:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dweebd.com/ruby/bool_attr_accessor-for-convenient-question-marks/#comment-31</guid>
		<description>I don&#039;t know if you&#039;ve looked at the implementation of #instance_values, but it&#039;s creating a hash of every ivar on each access.  That&#039;s not very efficient, and it&#039;s going to leave a lot of clutter for the GC.  I think it&#039;s best to keep it simple like instance_variable_get(&quot;@#{arg}&quot;).</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know if you&#8217;ve looked at the implementation of #instance_values, but it&#8217;s creating a hash of every ivar on each access.  That&#8217;s not very efficient, and it&#8217;s going to leave a lot of clutter for the GC.  I think it&#8217;s best to keep it simple like instance_variable_get(&#8220;@#{arg}&#8221;).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.273 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-03 17:24:00 -->
