On Mon, Jul 6, 2009 at 2:52 PM, s.ross<[email protected]> wrote: > > On Jul 5, 2009, at 8:44 PM, Rick wrote: > >> >> I currently decided to just use something like: >> >> def time_to_seconds time_display >> time = time_display.split(":") >> seconds = 0 >> modifiers = [ 1, 60, 360 ] >> time.each_with_index do | t, i | >> seconds = seconds + ( t.to_i * modifiers[time.length -1 - i] ) >> end >> return seconds >> end >> > > If you're just looking for a quick way to convert from hh:mm:ss to > seconds, how about: > > time_string.split(':').inject(0){|a, m| a = a * 60 + m.to_i} >
Wow! That looks awesome. I'm new to ruby so just looked into the inject method. I'll test it shortly. Thanks a lot. (It looks like it should work if you provided just minutes and seconds 10:04 or hours:min:sec 1:14:05 ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

