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?`.
How about using Array?

```
actions = [
    ['[:a, :b, :c, :d]', 'raise "private cannot be active"'],
    ['[:a, :b, :c]', 'raise "shared cannot be active"'],
    ['[:a, :b]', '[:a]']
]

x = [:private?, :shared?, :public?].find_index { |i| send(i) }
y = [:not_active?, :active?].find_index { |i| send(i) }

if x and y
    eval(actions[x][y])
else
    raise "not recognized"
end

```