[#86755] [Ruby trunk Feature#14723] [WIP] sleepy GC — normalperson@...
Issue #14723 has been reported by normalperson (Eric Wong).
6 messages
2018/04/29
[ruby-core:86576] [Ruby trunk Feature#8573] Add String#format method(not an alias of String#%)
From:
shyouhei@...
Date:
2018-04-18 09:59:19 UTC
List:
ruby-core #86576
Issue #8573 has been updated by shyouhei (Shyouhei Urabe).
bozhidar (Bozhidar Batsov) wrote:
> naruse (Yui NARUSE) wrote:
> > Show concrete use case.
>
> How about simply:
>
> ~~~ ruby
> "Hello, %s %s!".format("Mr.", "Bond")
> ~~~
That's too simple. What we need is how the requested feature _improves_ the situation. What's wrong with the status-quo? and how is that relaxed using String#format?
----------------------------------------
Feature #8573: Add String#format method(not an alias of String#%)
https://bugs.ruby-lang.org/issues/8573#change-71518
* Author: bozhidar (Bozhidar Batsov)
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
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/
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>