<?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: Encapsulation and don&#8217;t repeat yourself</title>
	<atom:link href="http://duncan.mac-vicar.com/blog/archives/283/feed" rel="self" type="application/rss+xml" />
	<link>http://duncan.mac-vicar.com/blog/archives/283#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
	<description>homepage</description>
	<lastBuildDate>Mon, 05 Jul 2010 12:56:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: duncan</title>
		<link>http://duncan.mac-vicar.com/blog/archives/283/comment-page-1#comment-96094</link>
		<dc:creator>duncan</dc:creator>
		<pubDate>Sun, 23 Dec 2007 00:25:26 +0000</pubDate>
		<guid isPermaLink="false">http://duncan.mac-vicar.com/blog/archives/283#comment-96094</guid>
		<description>&lt;p&gt;Well, I don&#039;t think it is possible in that way.&lt;/p&gt;

&lt;p&gt;Ruby does the trick because an assignment on a object member is done by calling the method member= on the object.&lt;/p&gt;

&lt;p&gt;attr_accessor is just a function which generates the most simple case on which a member variable of the same name is assigned.&lt;/p&gt;

&lt;p&gt;Even if you can define&lt;/p&gt;

&lt;p&gt;def member=(a,b)
  # do something
end
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;there is no way to call this using the assignment syntax.&lt;/p&gt;

&lt;p&gt;You could of course do obj.send and send the method name and parameters to reach that method.&lt;/p&gt;

&lt;p&gt;What you can actually do, is define the setter to accept an array of arguments:&lt;/p&gt;

&lt;p&gt;require &#039;pp&#039;&lt;/p&gt;

&lt;p&gt;class Foo
  def bah=(*opts)
    pp *opts
  end
end&lt;/p&gt;

&lt;p&gt;f = Foo.new
f.bah = 1
f.bah = 1, { :param =&gt; 1}
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;In the first case, you will get an integer, in the second case, an array where the first element is the integer, and the second element is a hash with the options.&lt;/p&gt;

&lt;p&gt;My experience with methods taking bool flags to modify behavior is not good :-(&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Well, I don&#8217;t think it is possible in that way.</p>

<p>Ruby does the trick because an assignment on a object member is done by calling the method member= on the object.</p>

<p>attr_accessor is just a function which generates the most simple case on which a member variable of the same name is assigned.</p>

<p>Even if you can define</p>

<p>def member=(a,b)
  # do something
end
</p>

<p>there is no way to call this using the assignment syntax.</p>

<p>You could of course do obj.send and send the method name and parameters to reach that method.</p>

<p>What you can actually do, is define the setter to accept an array of arguments:</p>

<p>require 'pp'</p>

<p>class Foo
  def bah=(*opts)
    pp *opts
  end
end</p>

<p>f = Foo.new
f.bah = 1
f.bah = 1, { :param =&gt; 1}
</p>

<p>In the first case, you will get an integer, in the second case, an array where the first element is the integer, and the second element is a hash with the options.</p>

<p>My experience with methods taking bool flags to modify behavior is not good <img src='http://duncan.mac-vicar.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Moore</title>
		<link>http://duncan.mac-vicar.com/blog/archives/283/comment-page-1#comment-96092</link>
		<dc:creator>Richard Moore</dc:creator>
		<pubDate>Fri, 21 Dec 2007 14:52:30 +0000</pubDate>
		<guid isPermaLink="false">http://duncan.mac-vicar.com/blog/archives/283#comment-96092</guid>
		<description>&lt;p&gt;Having default accessors seems like a nice technique. Do they extend to allowing you to add additional parameters? eg. To migrate to something like setFormatter( Formatter, bool deep = true );?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Having default accessors seems like a nice technique. Do they extend to allowing you to add additional parameters? eg. To migrate to something like setFormatter( Formatter, bool deep = true );?</p>]]></content:encoded>
	</item>
</channel>
</rss>
