<?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: Enumerations and Ruby</title>
	<atom:link href="http://www.rubyfleebie.com/enumerations-and-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rubyfleebie.com/enumerations-and-ruby/</link>
	<description>Because programming should be fun</description>
	<lastBuildDate>Wed, 04 Jan 2012 05:17:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: dB.</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-1385</link>
		<dc:creator>dB.</dc:creator>
		<pubDate>Wed, 16 Mar 2011 21:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-1385</guid>
		<description>Let&#039;s make some small changes and make this Enum structure reusable - http://code.dblock.org/ShowPost.aspx?id=184.</description>
		<content:encoded><![CDATA[<p>Let&#8217;s make some small changes and make this Enum structure reusable &#8211; <a href="http://code.dblock.org/ShowPost.aspx?id=184" rel="nofollow">http://code.dblock.org/ShowPost.aspx?id=184</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidy Diop</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-948</link>
		<dc:creator>Sidy Diop</dc:creator>
		<pubDate>Thu, 22 Apr 2010 00:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-948</guid>
		<description>Hi,
Another thing you could do (if you just need the integer values of associated symbols) is:
Colors = [ RED = 0, YELLOW = 1, GREEN = 3]
Then you can just loop doing: COLORS.each do { &#124;x&#124; do_something x }
You can access COLORS[RED].  Of course, COLORS would be a global if you need it everywhere.  But again, you can encapsulate it in a module if you wish.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Another thing you could do (if you just need the integer values of associated symbols) is:<br />
Colors = [ RED = 0, YELLOW = 1, GREEN = 3]<br />
Then you can just loop doing: COLORS.each do { |x| do_something x }<br />
You can access COLORS[RED].  Of course, COLORS would be a global if you need it everywhere.  But again, you can encapsulate it in a module if you wish.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-859</link>
		<dc:creator>Brent</dc:creator>
		<pubDate>Wed, 19 Aug 2009 20:46:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-859</guid>
		<description>very helpful (even comments), thanks!!</description>
		<content:encoded><![CDATA[<p>very helpful (even comments), thanks!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-855</link>
		<dc:creator>jeff</dc:creator>
		<pubDate>Wed, 15 Jul 2009 01:06:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-855</guid>
		<description>Might also take a look at enumerated_attribute: http://github.com/jeffp/enumerated_attribute/tree/master.  It works like...

enum_attr :gear, %w(reverse ^neutral first second third)</description>
		<content:encoded><![CDATA[<p>Might also take a look at enumerated_attribute: <a href="http://github.com/jeffp/enumerated_attribute/tree/master" rel="nofollow">http://github.com/jeffp/enumerated_attribute/tree/master</a>.  It works like&#8230;</p>
<p>enum_attr :gear, %w(reverse ^neutral first second third)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-847</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Thu, 25 Jun 2009 00:47:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-847</guid>
		<description>Hey Thanks for the links!</description>
		<content:encoded><![CDATA[<p>Hey Thanks for the links!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karlin Fox</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-846</link>
		<dc:creator>Karlin Fox</dc:creator>
		<pubDate>Wed, 24 Jun 2009 19:16:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-846</guid>
		<description>You may also be interested in Enumeration: http://github.com/karlin/enumeration/tree/master</description>
		<content:encoded><![CDATA[<p>You may also be interested in Enumeration: <a href="http://github.com/karlin/enumeration/tree/master" rel="nofollow">http://github.com/karlin/enumeration/tree/master</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allex</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-502</link>
		<dc:creator>Allex</dc:creator>
		<pubDate>Thu, 03 Jan 2008 20:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-502</guid>
		<description>Look at &lt;a href=&quot;http://elhumidor.blogspot.com/2007/11/renum-ruby-enum-gem.html&quot; rel=&quot;nofollow&quot;&gt;Renum&lt;/A&gt; - &quot;a Ruby enum gem&quot;.</description>
		<content:encoded><![CDATA[<p>Look at <a href="http://elhumidor.blogspot.com/2007/11/renum-ruby-enum-gem.html" rel="nofollow">Renum</a> &#8211; &#8220;a Ruby enum gem&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-344</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Mon, 27 Aug 2007 16:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-344</guid>
		<description>Alex,

That&#039;s a good question. Instead of using a Fixnum as the value, you could use a Hash :

class Status
Complete={:value =&gt; 0, :string =&gt; &quot;complete&quot;}
Queued={:value =&gt; 1, :string =&gt; &quot;queued&quot;}
Ready={:value =&gt; 2, :string =&gt; &quot;ready&quot;}
Processing={:value =&gt; 3, :string =&gt; &quot;processing&quot;}
Waiting={:value =&gt; 4, :string =&gt; &quot;waiting&quot;}
end

status = Status::Waiting
status[:value] # output : 4
status[:string] # output : waiting

There might be better ways to achieve what you want, but I think this solution would work fine.</description>
		<content:encoded><![CDATA[<p>Alex,</p>
<p>That&#8217;s a good question. Instead of using a Fixnum as the value, you could use a Hash :</p>
<p>class Status<br />
Complete={:value => 0, :string => &#8220;complete&#8221;}<br />
Queued={:value => 1, :string => &#8220;queued&#8221;}<br />
Ready={:value => 2, :string => &#8220;ready&#8221;}<br />
Processing={:value => 3, :string => &#8220;processing&#8221;}<br />
Waiting={:value => 4, :string => &#8220;waiting&#8221;}<br />
end</p>
<p>status = Status::Waiting<br />
status[:value] # output : 4<br />
status[:string] # output : waiting</p>
<p>There might be better ways to achieve what you want, but I think this solution would work fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Egg</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-343</link>
		<dc:creator>Alex Egg</dc:creator>
		<pubDate>Sat, 25 Aug 2007 06:10:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-343</guid>
		<description>Consider this enum of the style you describe:

  class Status
      Complete=0
      Queued=1
      Ready=2
      Processing=3
      Waiting=4
  end

now say I have an instance of this status:

status=Status::Waiting

How could I get this as a string that says &quot;Waiting&quot;? Even thought status is 4. Maybe create a class method in Status called to_string or something?</description>
		<content:encoded><![CDATA[<p>Consider this enum of the style you describe:</p>
<p>  class Status<br />
      Complete=0<br />
      Queued=1<br />
      Ready=2<br />
      Processing=3<br />
      Waiting=4<br />
  end</p>
<p>now say I have an instance of this status:</p>
<p>status=Status::Waiting</p>
<p>How could I get this as a string that says &#8220;Waiting&#8221;? Even thought status is 4. Maybe create a class method in Status called to_string or something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-300</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Thu, 12 Jul 2007 21:44:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-300</guid>
		<description>Yes, you are right siroj. The enum described in this article was not an enum in the pure sense of the word... as it isn&#039;t a &quot;type&quot; per se.

Most of the time, I only need the kind of enum described in this article... or I don&#039;t need an enum at all. I just like to &quot;group names under a common namespace&quot; for code readability. I rarely need  something fancier.

Thanks for your comment</description>
		<content:encoded><![CDATA[<p>Yes, you are right siroj. The enum described in this article was not an enum in the pure sense of the word&#8230; as it isn&#8217;t a &#8220;type&#8221; per se.</p>
<p>Most of the time, I only need the kind of enum described in this article&#8230; or I don&#8217;t need an enum at all. I just like to &#8220;group names under a common namespace&#8221; for code readability. I rarely need  something fancier.</p>
<p>Thanks for your comment</p>
]]></content:encoded>
	</item>
</channel>
</rss>

