RamJet
RamJet

Reputation: 313

Ruby/Rails equivalent to a C++ enum

My rails app can make telephone calls. I want a set of constants that define how calls will be conducted. When a call starts, one of three things could happen, depending on a configuration constant. They are

1) Ask the user to press a key to start the conversation

2) Ask the user to say continue to start the conversation

3) Start the conversation immediately when the phone is answered

The operation modes are mutually exclusive. If you press a key to start a conversation, you can't say continue to start a conversation, etc etc. In C++ this would be an enum. What's the preferred ruby/rails way to do this. An example showing how to construct the constant and how to use it in code would be greatly appreciated.

Upvotes: 2

Views: 112

Answers (1)

Eric Duminil
Eric Duminil

Reputation: 54283

For enums in Rails, I suggest Rails Enums ;)

Upvotes: 1

Related Questions