-----BEGIN PGP SIGNED MESSAGE-----
(I started writing this earlier but see your question has been
answered meanwhile; I’ll send it anyway, as the extra information may
be helpful. )
When a number such as m_counter is interpolated within a string, it
gets converted to a string representation if possible (using .to_s).
That is why your puts line works. The methods ljust() and rjust() are
called on strings, so one way to accomplish what you’re looking for
would be to do something like
puts m_counter.to_s.ljust(10) + ...
although I suspect you might be looking for rjust() not ljust(), as
numbers as often right-aligned (although this depends on whether
you’re working with decimal places).
A different, and arguably pleasanter, way of accomplishing this would
be to use a string-format approach. For this, you can specify a string
of formats and apply it to an array of values. e.g.
puts "%10s%10s%10s%10s%10s" %
That is the equivalent of .rjust(10) for each; for .ljust(10), use
“%-10s” instead of “%10s”.
Two excellent links for further study of this approach are:
On 14/10/2013 01:00, Greg H. wrote:
with the ljust next to it it gives me an error message of course.
So basically my question is how do I print out more than 1 variable
with methods next to them. (Sorry if I used the wrong definitions…
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
-----END PGP SIGNATURE-----