我正在使用Ruby on Rails 3.2.9和Ruby 1.9.3。我有以下case
報表:如何重構嵌套case語句(在這種情況下)?
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
如何重構上述代碼?
@Andrew馬歇爾 - 我不明白你爲什麼刪除(至少)'的Ruby-on-rails'標記,因爲它可能是有一些回報率的方法,可以幫助重構張貼在代碼這個問題。 – user12882
你能解釋更多關於'active?'和'not_active?'方法嗎? 它們是互補的,我的意思是這種情況'not_active? ==!活躍?'? – Khaled
你的代碼如何能夠「提升」不被識別的「'? – oldergod