<?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: Variable methods and accessors in Ruby</title>
	<atom:link href="http://www.beyondcoding.com/2008/05/26/variable-methods-and-accessors-in-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beyondcoding.com/2008/05/26/variable-methods-and-accessors-in-ruby/</link>
	<description>Follow us on Twitter: @fredwu and @scotti3g</description>
	<lastBuildDate>Sun, 05 Sep 2010 20:06:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: adz</title>
		<link>http://www.beyondcoding.com/2008/05/26/variable-methods-and-accessors-in-ruby/comment-page-1/#comment-226</link>
		<dc:creator>adz</dc:creator>
		<pubDate>Tue, 17 Jun 2008 06:28:42 +0000</pubDate>
		<guid isPermaLink="false">http://thislab.com/?p=40#comment-226</guid>
		<description>This is usually a bad idea - don&#039;t go accessing those private object internals!!

If you want to make them public, use attr_accessor...

&lt;code&gt;
class Foo
  attr_accessor :dynamic_accessor
end

f= Foo.new
f.dynamic_accessor = &#039;blah&#039;
&lt;/code&gt;

If you really want to go peeking into those private internals, you can use instance_variable_get or set...

&lt;code&gt;
f.instance_variable_set(:some_var, &#039;some_value&#039;)
# same as inside class Foo doing @some_value
&lt;/code&gt;

Check out the RDOC for Object class (every objects parent): http://www.ruby-doc.org/core/classes/Object.html


&lt;code&gt;
# I kind of like &#039;send&#039; as a method:
funcname = &#039;dynamic_method&#039;
foo.send(funcname)  # no need for quotes here
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>This is usually a bad idea &#8211; don&#8217;t go accessing those private object internals!!</p>
<p>If you want to make them public, use attr_accessor&#8230;</p>
<p><code><br />
class Foo<br />
  attr_accessor :dynamic_accessor<br />
end</p>
<p>f= Foo.new<br />
f.dynamic_accessor = 'blah'<br />
</code></p>
<p>If you really want to go peeking into those private internals, you can use instance_variable_get or set&#8230;</p>
<p><code><br />
f.instance_variable_set(:some_var, 'some_value')<br />
# same as inside class Foo doing @some_value<br />
</code></p>
<p>Check out the RDOC for Object class (every objects parent): <a href="http://www.ruby-doc.org/core/classes/Object.html" rel="nofollow">http://www.ruby-doc.org/core/classes/Object.html</a></p>
<p><code><br />
# I kind of like 'send' as a method:<br />
funcname = 'dynamic_method'<br />
foo.send(funcname)  # no need for quotes here<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matthew wastrodowski</title>
		<link>http://www.beyondcoding.com/2008/05/26/variable-methods-and-accessors-in-ruby/comment-page-1/#comment-225</link>
		<dc:creator>matthew wastrodowski</dc:creator>
		<pubDate>Wed, 04 Jun 2008 18:49:44 +0000</pubDate>
		<guid isPermaLink="false">http://thislab.com/?p=40#comment-225</guid>
		<description>I&#039;m a lame ruby guy who has a new project that has to work in php. So I&#039;m the opposite of you. Thanks for the helpful post, although call_user_func isn&#039;t exactly like send because it doesn&#039;t get called on an object.

I miss some of the ruby blocks (locally defined functions) already.

If you really wanted the assign accessors on an object for everything, just override method_missing on an object to automatically set a class variable if called with a &quot;something=&quot; method. :)</description>
		<content:encoded><![CDATA[<p>I&#8217;m a lame ruby guy who has a new project that has to work in php. So I&#8217;m the opposite of you. Thanks for the helpful post, although call_user_func isn&#8217;t exactly like send because it doesn&#8217;t get called on an object.</p>
<p>I miss some of the ruby blocks (locally defined functions) already.</p>
<p>If you really wanted the assign accessors on an object for everything, just override method_missing on an object to automatically set a class variable if called with a &#8220;something=&#8221; method. :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
