P
Ps Lordcrap
Hi all, I started learning ruby two weeks ago and I'm loving it. I'm
coding some date/time program to practice at the moment and I hit a
wall. I need a way to ask ruby whether or not a certain operation will
return an error. (I've tried google, I've searched this forum, the
manuals and IRC but to no avail, so I'm turning to you guys)
I don't think the code is necessary since it's probably a really easy
thing such as ".isitanerror" or whatever but here it is anyway.
To put you in context, before this, the program checks that all the
input was integers and well formated and then inputs the whole thing
into an array called "thedate". Now I want to check if the array of
integers is a date or not (i.e. if someone enters '99' in the 'hour'
slot I want the program to know it's not correct.) When I enter a real
date it works, when I enter malformated gibberish the code before
catches it but if I enter well formated "not date" numbers, the last
line before the "end" returns an error - so again, what I want to do is
to test wether or not that last line will return an error without
running it and breaking the program.
if problems != true
dateformated = thedate[0].to_s + '-' + thedate[1].to_s + '-' +
thedate[2].to_s + 'T' + thedate[3].to_s + ':' + thedate[4].to_s + ':' +
thedate[5].to_s
birthindate = DateTime.parse(dateformated)
end
coding some date/time program to practice at the moment and I hit a
wall. I need a way to ask ruby whether or not a certain operation will
return an error. (I've tried google, I've searched this forum, the
manuals and IRC but to no avail, so I'm turning to you guys)
I don't think the code is necessary since it's probably a really easy
thing such as ".isitanerror" or whatever but here it is anyway.
To put you in context, before this, the program checks that all the
input was integers and well formated and then inputs the whole thing
into an array called "thedate". Now I want to check if the array of
integers is a date or not (i.e. if someone enters '99' in the 'hour'
slot I want the program to know it's not correct.) When I enter a real
date it works, when I enter malformated gibberish the code before
catches it but if I enter well formated "not date" numbers, the last
line before the "end" returns an error - so again, what I want to do is
to test wether or not that last line will return an error without
running it and breaking the program.
if problems != true
dateformated = thedate[0].to_s + '-' + thedate[1].to_s + '-' +
thedate[2].to_s + 'T' + thedate[3].to_s + ':' + thedate[4].to_s + ':' +
thedate[5].to_s
birthindate = DateTime.parse(dateformated)
end