Project

General

Profile

Actions

Feature #8573

closed

Add String#format method(not an alias of String#%)

Added by bozhidar (Bozhidar Batsov) almost 11 years ago. Updated about 6 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:55682]

Description

I think it'd be great if String included a method similar to % that accepts variable number of arguments (like sprintf). This is trivial to implement as you're certainly aware.

Here's one implementation suggestion:

class String
def format(*args)
super(self, *(args.flatten))
end
end

This would make the new method behave both like sprintf/format and String#%. I think this minor improvement would definitely be in the spirit of making more programmers happy :-)

Here a bit more on the topic - http://batsov.com/articles/2013/06/27/the-elements-of-style-in-ruby-number-2-favor-sprintf-format-over-string-number-percent/

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0