Class: TTY::Option::InvalidArity
- Inherits:
-
ParseError
- Object
- ParseError
- TTY::Option::InvalidArity
- Defined in:
- lib/tty/option/errors.rb
Overview
Raised when number of parameter arguments doesn’t match
Constant Summary collapse
- MESSAGE =
"%<type>s '%<name>s' should appear %<expect>s but appeared %<actual>s"
Instance Attribute Summary
Attributes inherited from ParseError
Instance Method Summary collapse
-
#initialize(param_or_message, arity = nil) ⇒ InvalidArity
constructor
A new instance of InvalidArity.
-
#pluralize(noun, count = 1) ⇒ Object
private
Pluralize a noun.
Methods inherited from ParseError
Constructor Details
#initialize(param_or_message, arity = nil) ⇒ InvalidArity
Returns a new instance of InvalidArity.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tty/option/errors.rb', line 73 def initialize(, arity = nil) if .is_a?(Parameter) @param = prefix = param.arity < 0 ? "at least " : "" expected_arity = param.arity < 0 ? param.arity.abs - 1 : param.arity = format(MESSAGE, type: param.to_sym, name: param.name, expect: prefix + pluralize("time", expected_arity), actual: pluralize("time", arity)) else = end super() end |
Instance Method Details
#pluralize(noun, count = 1) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pluralize a noun
94 95 96 |
# File 'lib/tty/option/errors.rb', line 94 def pluralize(noun, count = 1) "#{count} #{noun}#{'s' unless count == 1}" end |