【发布时间】:2014-01-15 01:07:00
【问题描述】:
与其让我的 Ruby 对象的构造函数抱怨给定的参数数量(在错误参数的情况下),我希望消息准确地列出预期的内容。
def initialize a, b, c
begin
@a = a
@b = b
@c = c
rescue ArgumentError
raise ArgumentError, "my custom error message"
end
end
显然这行不通,但希望这能让你的想法得到理解。我只想覆盖这个类的默认 ArgumentError 消息。
【问题讨论】:
标签: ruby class overriding argument-error