On May 31, 2014, at 6:18, Robert Klemme <shortcutter / googlemail.com> =
wrote:

> 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"

Not true anymore:

% ri String.%
=3D String.%

(from ruby core)
=
--------------------------------------------------------------------------=
----
  str % arg   -> new_str

=
--------------------------------------------------------------------------=
----

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.

  "%05d" % 123                              #=3D> "00123"
  "%-5s: %08x" % [ "ID", self.object_id ]   #=3D> "ID   : 200e14d6"
  "foo =3D %{foo}" % { :foo =3D> 'bar' }        #=3D> "foo =3D bar"