Project

General

Profile

Actions

Feature #3450

closed

Format Strings with Named Arguments & Hash#default

Added by runpaint (Run Paint Run Run) almost 14 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
[ruby-core:30803]

Description

=begin
Is it intentional that the, undocumented, feature #442 (named arguments in format strings) ignores the Hash's default value?

hash = {greeting: 'Hello'}.tap{|h| h.default = 'World'}
'%{greeting}, %{greeted}' % hash
#=> KeyError: key{greeted} not found

It's quite common for templates to use default values. In interface localisation, untranslated strings may need to be substituted for the equivalent in the native language, or replaced with a generic string in the target language. When building reports with format strings, a default value of an empty string allows unexpanded format sequences to be non-fatal. In both cases, a default proc would provide even further flexibility.

Another perspective is that this behavior unnecessarily breaks the abstraction that default values are just like any other.
=end


Files

3450.patch (578 Bytes) 3450.patch judofyr (Magnus Holm), 06/18/2010 07:07 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0