Actions
Feature #16779
closedAdd sprintf %q format option
Feature #16779:
Add sprintf %q format option
Status:
Rejected
Assignee:
-
Target version:
-
Description
It would be great to have format option for quoted string for sprintf (like golang sprintf),
it's particularly useful to format log message for example.
Currently we have to do this:
sprintf("%s", some_value.inspect.dump)
I propose to introduce the %q format option which allow to do this:
sprintf("%q", some_value)
Files
Updated by gearnode (Bryan Frimin) over 5 years ago
- Description updated (diff)
Updated by gearnode (Bryan Frimin) over 5 years ago
- Description updated (diff)
Updated by gearnode (Bryan Frimin) over 5 years ago
The github pull request: https://github.com/ruby/ruby/pull/3019
Updated by Eregon (Benoit Daloze) over 5 years ago
Isn't %p enough (which uses #inspect)?
Updated by Eregon (Benoit Daloze) over 5 years ago
.inspect.dump double quotes, that doesn't seem readable/useful to me:
puts sprintf("%s", "abc".inspect.dump)
# "\"abc\""
Updated by gearnode (Bryan Frimin) over 5 years ago
I am not aware of %p format option, this option exactly did what i try to solve.
Thanks.
Someone can close this issue?
Updated by Eregon (Benoit Daloze) over 5 years ago
- Status changed from Open to Rejected
Updated by Eregon (Benoit Daloze) over 5 years ago
%p is part of the documentation of sprintf but maybe it's not so clear.
PR welcome to improve that documentation.
Actions