说我有这段代码:
class A
def initialize
myMethod()
print "This should not be printed"
end
def myMethod
#here
end
end
obj = A.new
print "This should be printed"
是否有任何命令我可以放置而不是“#here”退出'obj'对象并继续下一个语句? (打印“这应该打印”)
答案 0 :(得分:3)
throw / catch会这样做:
class A
def initialize
catch :init_done do
myMethod()
print "This should not be printed"
end
end
def myMethod
throw :init_done
end
end
obj = A.new
print "This should be printed"