Project

General

Profile

Actions

Feature #5558

open

String#% strange arity errors

Added by trans (Thomas Sawyer) about 13 years ago. Updated almost 7 years ago.

Status:
Assigned
Target version:
-
[ruby-core:40697]

Description

When the number of arguments do not match the number of % parameters, the String#% method has some odd behavior.

When too many, it seems to work fine, ignoring the extra arguments.

"%s" % [1,2] #=> "1"

But if $DEBUG = true,

"%s" % [1,2] #=> ArgumentError: too many arguments for format string

That doesn't seem right. Is it an error or isn't it?

For too few arguments it is always an error:

"%s" % [] #=> ArgumentError: too few arguments

Personally, I think it should use '' for missing arguments. That would make it more flexible in practice.

I consider the first $DEBUG issue a bug, and the later a feature. But I'll just call it a feature altogether to make things easier.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0