You should make sure you know why you are using printf and / or using =
interpolation. If either s1 or s2 contained printf escape sequences (for =
example %d) things would get interesting:

[1] pry(main)> s1 =3D "I'll have 10%"
=3D> "I'll have 10%"
[2] pry(main)> n1 =3D 00
=3D> 0
[3] pry(main)> s2 =3D 'string'
=3D> "string"
[4] pry(main)> n2 =3D 26
=3D> 26
[5] pry(main)> printf "| #{s1.ljust(20)} | #{n1} |"
ArgumentError: malformed format string - %|
from (pry):5:in `printf'
[6] pry(main)> printf "| #{s2.ljust(20)} | #{n2} |"
| string               | 26 |=3D> nil

You might want to consider just using printf:

[7] pry(main)> printf '| %-20s | %02d |', s1, n1
| I'll have 10%        | 00 |=3D> nil
[8] pry(main)> printf '| %-20s | %02d |', s2, n2
| string               | 26 |=3D> nil

Hope this helps,

Mike


On Mar 7, 2014, at 9:54 AM, Jaimin Pandya <lists / ruby-forum.com> wrote:

> Robert Klemme wrote in post #1139149:
>> On Fri, Mar 7, 2014 at 1:41 PM, Jaimin Pandya <lists / ruby-forum.com>
>> wrote:
>>=20
>>> By using printf, spacing problem happen as I mentioned in my recent
>>> post.
>>=20
>> Please show the code.
>>=20
>=20
> I used printf as follow:
>=20
> s1 =3D 'first string'
> n1 =3D 00
> s2 =3D 'string'
> n2 =3D 26
>=20
> printf "| #{s1.ljust(20)} | #{n1} |"
> printf "| #{s2.ljust(20)} | #{n2} |"
>=20
> then I got spacing problem.
>=20
> Thank you.
>=20
> --=20
> Posted via http://www.ruby-forum.com/.

--=20

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.