On Jan 15, 2008 11:56 AM, Ak 756 <macro.peng / gmail.com> wrote: > Hi > > I hava a string indicate a hh/mm/ss time and some other strings indicat > operations on the string. For example , string "+5" means add 5 second. > > Here is my code: > > def modifytime(s1,s2) > if s2[0,1] == "+" > (Time.parse(s1)+s2[1,s2.length-1].to_i).to_s.split[3] > else if s2[0,1] == "-" > (Time.parse(s1)-s2[1,s2.length-1].to_i).to_s.split[3] > end > end > end > > time = "00:11:20" > add5second = "+5" > sub50second = "-50" > > puts modifytime(time,add5second) => "00:11:25" > puts modifytime(time,sub50second) => "00:10:30" > > The result is what I expected but I think the modifytime is ugly. > Can I use 'eval' so that I don't need to judge "+" or "-"? > Or, any elegant solutions? > Thanks in advance. http://p.ramaze.net/191 ^ manveru