Thanks to all who replied to my question.

I want to mention one thing.
One drawback of ruby's #{name} mechanism is that the variable 'name' must
exist before I setup the format and another drawback is that when I setup
the format the result string is already made (returned) and cannot be
delayed (if I'm correct...).
Sometimes I want to make the format first, especially when I write scripts
for web pages with python (now ruby :-)).

In python for ASP, for instance, I frequently write the following style
code.

html = """
    <tr>
        <td>%(name)s</td>
        <td>%(age)d</td>
    </tr>
"""
di = {
    "name": get_name_from_db(),
    "age": get_age_from_db()
}
Response.Write(html % di)

Well, I may change the sequence (get the values first and setup the
formatting string).
However, in the above case, formatting is outer bound and the values are
details.
My brain feels more comfortable in this way...;^)

Sam



"GGarramuno" <GGarramuno / aol.com> wrote in message
news:af53b0ba.0406012346.42f73e84 / posting.google.com...
> nobu.nokada / softhome.net wrote in message
news:<200406020151.i521pOHY005774 / sharui.nakada.niregi.kanuma.tochigi.jp>...
> > Hi,
> >
> > At Wed, 2 Jun 2004 03:43:42 +0900,
> > Sam Sungshik Kong wrote in [ruby-talk:102028]:
> > > s = "My name is %(name)s and my age is %(age)d." % {"name": "Sam",
"age": 34}
> >
> > > I know that ruby has "#{name}" expression.
> > > But that requires a variable named "name" in advance.
> > > I want to bind the format string and data later.
> >
> > I proposed that feature once in [ruby-dev:16351], though
> > rejected, but still I think that it would be useful for I18N.
> > Is it worth for RCR?
>
> Do you have an example on how would you use this?  I ask because I
> would also vote strongly against it.
>
> One of the things that I really loved about ruby while learning it was
> its "#{}" syntax, as it seemed to me a much more consistent way of
> achieving what sprintf, $, %, etc. have been trying for years to
> achieve in languages like C, perl, python, etc.
>
> To achieve the above for quick testing, it is much easier and readable
> to just do:
> s = "My name is #{'Sam'} and my age is #{34}."
>
> Then, later, if the need for a hash or an object really does arise,
> you can easily do:
> p = { :name => 'Sam', :age => 34 }
> s = "My name is #{p[:name]} and my age is #{p[:age]}."
>
> If you have say a Person object with proper accessors, it is even
> nicer to read:
> p = Person.new(:name=>'Sam', :age => 34)
> s = "My name is #{p.name} and my age is #{p.age}."
>
> Better yet, if you call a simple function within, it is still very
> readable.  Ex:
> s = "My name is #{p.name.upcase} and my age is #{p.age}."
>
> The %s syntax is anything but readable once you have more than 3
> elements.  Using a hash to try to clarify it seems to me more of a
> crutch for languages that do not support ruby's extremely powerful
> "#{}" formating.
> That syntax still forces me to look for meaning of the text format
> string in two different places (in the location of the text and at the
> end of it), instead of in a single place as I read the string, which
> seems like a step backwards overall.