Question: I am using Ruby on Rails 3.2.9 and Ruby 1.9.3. I have following `case` statements:

```
case
when private?
  case
  when not_active? then [:a, :b, :c, :d]
  when active?     then raise "private cannot be active"
  else raise "not recognized"
  end
when shared?
  case
  when not_active? then [:a, :b, :c]
  when active?     then raise "shared cannot be active"
  else raise "not recognized"
  end
when public?
  case
  when not_active? then [:a, :b]
  when active?     then [:a]
  else raise "not recognized"
  end
else raise "not recognized"
end

```

How to refactor the above code?

Answer: 
```
raise "not recognized" unless private? or shared? or public?
raise "not recognized" unless not_active? or active?
raise "private cannot be active" if private? and active?
raise "shared cannot be active" if shared? and active?

[:a, *(:b unless active?), *(:c unless public?), *(:d if private?)]

```

---

By changing the error message, you can make it still more comfortable:

```
raise "visibility not recognized" unless private? or shared? or public?
raise "activeness not recognized" unless not_active? or active?
raise "active must be public" if active? and not public?

[:a, *(:b unless active?), *(:c unless public?), *(:d if private?)]

```

By the way, `inactive?` would be a better method name than `not_active?`.
An organized one:

```
CONDITIONS = 
  {"private?" => {"not_active?" => [:a, :b, :c, :d],
                  "active?"     => "private cannot be active"},
  {"shared?"  => {"not_active?" => [:a, :b, :c],
                  "active?"     => "shared cannot be active"},
  {"public?"  => {"not_active?" => [:a, :b],
                  "active?"     => [:a]}}

def foo(it)
  value = "not recognised"
  CONDITIONS.each do |k, v|
    if it.send(k.to_sym)
      v.each do |inner_k, inner_v|
        if it.send(inner_k.to_sym)
          value = inner_v
        end
      end
    end
  end

  raise value if (value.class.name == "String")

  value
end

```

In case of expansion you only need to make the CONDITIONS hash larger.