-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear Greg,
(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" %
[m_counter,payment,interest,principal,balance]
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:
Peace,
tiredpixel
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…
still new!)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSWzk7AAoJEOFolTkanF7VVb8H/0ef08qW+rLW2itGW6+OzOaN
EbWwTirThBE/B18pbC2C1vN2294fa5PHuIGmegCUqxy7NSx//sLZ3GM01hOCKcbz
v+WKHRsU63Pt2l8rp4u9TjabNsJJSpjZffgoFxShmRg3A7BdIUsWEfaVmER/g6js
y0Ekt9T4fIHl+58cAUpUMDT/dbcf0X+ED3sArTvn/SSuNtH9tgMsvgUL9RSuWwxe
cIdvfjoy9OiWwkn1av6KSzf0HuNXVRtCaMLHEyg4yGPol79pPvO0KoKgrv/1xe5y
QBHt6sF0AqUhvjmBhIsQedf0vI4YOUZwhOC43V9AgYXhi175HAwQTqYFDDfnVIE=
=wk6w
-----END PGP SIGNATURE-----