On Thu, Aug 16, 2012 at 11:37 PM, Charles Hixson
<[email protected]> wrote:
> I have a list of about 12 items that I wish to repeatedly store as part of a
> record in a file.  The obvious way to do this is to define a bunch of
> constant terms with values [1 .. 12].  But when I want to use them in the
> program, symbols would be more convenient.  Is there a better way to do this
> than just defining the constants, and using a pair of functions to convert
> to and from symbols?

There are some approaches to do enums in Ruby out there, e.g.
http://code.dblock.org/how-to-define-enums-in-ruby
http://stackoverflow.com/questions/75759/enums-in-ruby
http://www.lesismore.co.za/rubyenums.html

You'll find plenty more with your favorite search engine.

Other than that the two function approach probably works as well.  Or
you use two Hashes for both directions and not two functions.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to