与其让我的 Ruby 对象的构造函数抱怨给定的参数数量(如果参数错误),我希望消息准确地列出预期的内容。
def initialize a, b, c
begin
@a = a
@b = b
@c = c
rescue ArgumentError
raise ArgumentError, "my custom error message"
end
end
显然这是行不通的,但希望这能传达出这个想法。我只想覆盖这个类的默认 ArgumentError 消息。