我正在使用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