From: David Alan Black Date: 2000-12-20T17:37:35+09:00 Subject: [ruby-talk:7751] Re: Code sample for improvement Hello -- On Wed, 20 Dec 2000, Guy N. Hurst wrote: > I looked at the other samples and decided to give this a try. I > figured there might be a nice way to use the Time class for this. > Besides, there aren't 30 days in every month ;-) True... but the lump in the carpet has to end up somewhere. One could also say: 2 * (1 month's worth of seconds) doesn't always equal 2 months 3 days, and so forth: time = 2678400 (1..5).each do |i| x = time * i puts "#{x} seconds: #{x.to_time}" end 2678400 seconds: 1 month 5356800 seconds: 2 months 3 days 8035200 seconds: 3 months 3 days 10713600 seconds: 4 months 4 days 1 hour 13392000 seconds: 5 months 4 days 1 hour Obviously these make sense with regard to 1/1/1970, but for a given case it may be more relevant or informative to average things out. (Or did your ';-)' cover all this? :-) > In making this code, I am taking advantage of the fact that the > English words, including your accepted abbreviations "min" and > "sec", match the methods I will use from the Time class, which I use > as my workhorse. No tables are needed. Since this seems like a > useful method, I added it into the String and Integer classes. > Personally, I think this better reflects the Ruby way to do things. A bit of a conversation-stopper... :-) but anyway: doesn't it depend on what "things" one is doing? Your approach is a great way to translate seconds into an English representation of time since 1/1/1970. But I think there are legitimate reasons that one might interpret the seconds-to-English task differently. (By the way, I'm not specifically defending my own version of this -- I have nothing riding on that, nor any conviction that it couldn't be improved upon.) > I really like Ruby :-) Hey, I can beat that -- I even like the Ruby discussion list :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav