From: "Shot (Piotr Szotkowski)" Date: 2009-11-18T14:53:49+09:00 Subject: Re: How to time something? --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Brian Geds: > Heres what I have right now but it does > reset the sec. to zero it keeps going 61..62 > def seconds_minutes_string(seconds_elapsed) > seconds =3D seconds_elapsed % 59 > minutes =3D seconds / 60 > return minutes.to_s + ':' + seconds.to_s > end First, as Michael pointed out, you probably want to divide modulo 60, and you want the minutes to be based on seconds_elapsed rather than seconds. Second, each time you % and / the same number by the same integer, you might want to use Numeric#divmod instead: def time_str secs secs.divmod(60).join ':' end (57..62).map { |secs| time_str secs } # =3D> ["0:57", "0:58", "0:59", "1:0", "1:1", "1:2"] Third, as Rick pointed out, if you prefer 1:02 to 1:2, you can do this: def time_str secs '%d:%02d' % secs.divmod(60) end (57..62).map { |secs| time_str secs } # =3D> ["0:57", "0:58", "0:59", "1:00", "1:01", "1:02"] =E2=80=94 Shot (and, apparently, his ironic signature AI having a good day) --=20 It=E2=80=99s great to be smart =E2=80=99cause then you know stuff. --fUYQa+Pmc3FrFX/N Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAksDi+gACgkQi/mCfdEo8Uo4qgCgloKBDIPMwMyhctrw9FUF+aJj f04AnRyPQYORtUZeI4+N93V9XoGzy45+ =ihA5 -----END PGP SIGNATURE----- --fUYQa+Pmc3FrFX/N--