【发布时间】:2011-02-27 05:54:51
【问题描述】:
想象一下我有这样的课程:
class A
attr_accessor :a
attr_accessor :b
def check
raise "a must meet some condition" if !condition(@a)
raise "b must meet some condition" if !condition(@b)
end
def do_some_work
check()
# more work here
end
def do_some_more_work
check()
# other work here
end
end
在另一个方法而不是当前方法中为访问器设置先决条件是不好的做法吗?
【问题讨论】:
标签: ruby exception refactoring