On Jun 2, 2014, at 0:27, Robert Klemme <shortcutter / googlemail.com> =
wrote:

> On Mon, Jun 2, 2014 at 6:55 AM, Ryan Davis <ryand-ruby / zenspider.com> =
wrote:
>>=20
>> On May 31, 2014, at 6:18, Robert Klemme <shortcutter / googlemail.com> =
wrote:
>>=20
>>> On Fri, May 30, 2014 at 8:12 PM, Arup Rakshit
>>> <aruprakshit / rocketmail.com> wrote:
>>>=20
>>>> Does it mean I can use String#% to hash only when Hash will have =
keys as a
>>>> symbol ? Or there is a trick, that I am missing.
>>>=20
>>> String#% does not hash - it's a shortcut for sprintf():
>>>=20
>>> irB(mAin):008:0> "A%04dB" % 1
>>> =3D> "A0001B"
>>> irB(mAin):009:0> "A%04dB" % 34
>>> =3D> "A0034B"
>>> irB(mAin):010:0> "A%04dB%pX" % [34, 99]
>>> =3D> "A0034B99X"
>>> irB(mAin):011:0> "A%04dB%pX" % [34, [1,2]]
>>> =3D> "A0034B[1, 2]X"
>>>=20
>>> irb(main):012:0> sprintf "A%04dB", 1
>>> =3D> "A0001B"
>>> irb(main):013:0> sprintf "A%04dB", 34
>>> =3D> "A0034B"
>>> irb(main):014:0> sprintf "A%04dB%pX", 34, 99
>>> =3D> "A0034B99X"
>>> irb(main):015:0> sprintf "A%04dB%pX", 34, [1,2]
>>> =3D> "A0034B[1, 2]X"
>>=20
>> Not true anymore:
>=20
> What is not true any more? You are just confirming what I wrote above.

I read your statement to say that String#% doesn't handle hashes, tho on =
second reading you might have meant that it doesn't #hash. Not that I =
can figure out why you'd say such a thing. Arup's mail was pretty clear =
that he was using String#% with a hash argument.

>> % ri String.%
>> =3D String.%
>>=20
>> (from ruby core)
>> =
--------------------------------------------------------------------------=
----
>>  str % arg   -> new_str
>>=20
>> =
--------------------------------------------------------------------------=
----
>>=20
>> Format---Uses str as a format specification, and returns the result =
of
>> applying it to arg. If the format specification contains more than =
one
>> substitution, then arg must be an Array or Hash containing the values =
to
>> be substituted. See Kernel::sprintf for details of the format string.
>>=20
>>  "%05d" % 123                              #=3D> "00123"
>>  "%-5s: %08x" % [ "ID", self.object_id ]   #=3D> "ID   : 200e14d6"
>>  "foo =3D %{foo}" % { :foo =3D> 'bar' }        #=3D> "foo =3D bar"
>>=20
>=20
> Yes, exactly my point.

Not exactly your point. None of your examples of sprintf are like the =
last example of the String#% rdoc:

"foo =3D %{foo}" % { :foo =3D> 'bar' }

returns:

"foo =3D bar"

So you were confusing the issue when the OP was clearly using a hash =
argument.=