如果参数错误,如何取消对象创建?例子:
class MyClass
def initialize(a, b, c)
@a = @b = @c = nil
@a = a if a.is_a? Integer
@b = b if b.is_a? String
@c = c if c.is_a? Integer or c.is_a? Float
return nil if @a == nil or @b == nil or @c == nil # doesn't works
end
end
cl = MyClass.new('str', 'some', 1.0) # need cl to be nil because 1st param isn't Integer