我不知道是否应该验证传递给方法的参数是否属于某个类。在Ruby中验证参数?
例如。
def type(hash = {}, array = [])
# validate before
raise "first argument needs to be a hash" unless hash.class == Hash
raise "second argument needs to be an array" unless array.class == Array
# actual code
end
这样做是否聪明,还是只是繁琐和浪费时间来验证所有传递参数?
有没有这种情况,当你不想打扰时有这种额外的安全和环境?
分享您的经验!
这是真的。为什么验证你的程序员=) – 2010-08-05 02:11:23