title: Ruby Style Question: storing hash constant with different possible values
body: <p>This is more of a style question, I'm wondering what other people do.</p>
  
  <p>Let's say I have a field in my database called "status" for a blog post.   And I want it to have several possible values, like "draft", "awaiting review", and "posted", just as an example.</p>
  
  <p>Obviously we don't want to "hard code" in these magic values each time, that wouldn't be DRY.</p>
  
  <p>So what I sometimes do is something like this:</p>
  
  <pre><code>class Post
    STATUS = {
      :draft =&gt; "draft",
      :awaiting_review =&gt; "awaiting review",
      :posted =&gt; "posted"
    }
  
    ...
  
  end
  </code></pre>
  
  <p>Then I can write code referring to it later as <code>STATUS[:draft]</code> or <code>Post::STATUS[:draft]</code> etc.</p>
  
  <p>This works ok, but there are a few things I don't like about it.</p>
  
  <ol>
  <li>If you have a typo and call something like <code>STATUS[:something_that_does_not_exist]</code> it won't throw an error, it just returns nil, and may end up setting this in the database, etc before you ever notice a bug</li>
  <li>It doesn't look clean or ruby-ish to write stuff like <code>if some_var == Post::STATUS[:draft]</code> ...</li>
  </ol>
  
  <p>I dunno, something tells me there is a better way, but just wanted to see what other people do.  Thanks! </p>