<?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>Thu, 15 Jul 2010 19:48:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<item>
		<title>By: siroj</title>
		<link>http://www.rubyfleebie.com/enumerations-and-ruby/comment-page-1/#comment-298</link>
		<dc:creator>siroj</dc:creator>
		<pubDate>Thu, 12 Jul 2007 09:58:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/enumerations-and-ruby/#comment-298</guid>
		<description>Frank, I think what @Badaud means is enums in C# (I don&#039;t really know about enums in Java, maybe it&#039;s the same, I only used it once a year ago, already forgot). 

In C#, if you declare a method parameter to be some kind of enum, then you have to pass EXACTLY the MEMBER of that enum. So in C#, enums is more than just some constants grouped in one place, but it also has type information. If you pass different kind of enum than the one that method expected, then the compiler will happily report it as error to you.

But I think is quite impossible to do it in Ruby (actually, I haven&#039;t thinking about it :D), because usually we don&#039;t pay much attention to type information of an object. Event worse, actually Ruby has different concept about type (type-is-all-about-what-an-object-can-do vs type-is-all-about-object-class-hierarchy)</description>
		<content:encoded><![CDATA[<p>Frank, I think what @Badaud means is enums in C# (I don&#8217;t really know about enums in Java, maybe it&#8217;s the same, I only used it once a year ago, already forgot). </p>
<p>In C#, if you declare a method parameter to be some kind of enum, then you have to pass EXACTLY the MEMBER of that enum. So in C#, enums is more than just some constants grouped in one place, but it also has type information. If you pass different kind of enum than the one that method expected, then the compiler will happily report it as error to you.</p>
<p>But I think is quite impossible to do it in Ruby (actually, I haven&#8217;t thinking about it :D), because usually we don&#8217;t pay much attention to type information of an object. Event worse, actually Ruby has different concept about type (type-is-all-about-what-an-object-can-do vs type-is-all-about-object-class-hierarchy)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
