sentence = “Your ticket has expired since #{nb_of_days + ‘days’ if
nb_of_days<0} #{‘today’ if nb_of_days==0}”
But it doesn’t work!
Thank you for your help
I think you want to change that to a greater than…
sentence = “Your ticket has expired since #{nb_of_days + ’ days’ if
nb_of_days > 0}#{‘today’ if nb_of_days==0}”
And if that message is going to be read in English, then you should
change it to ‘#{nb_of_days} ago’ || ‘today’ without the since. i.e.
‘Your ticket expired 4 days ago’ or ‘Your ticket expired today’
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
Sorry, I didn’t actually run the code the first time! It was trying to
use Fixnum’s + method rather than String’s
This does work:
sentence = “Your ticket expired #{nb_of_days.to_s + ’ days ago’ if
nb_of_days > 0}#{‘today’ if nb_of_days==0}”
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
15:33:12 Temp$ ruby exp.rb
Your ticket expired today.
Your ticket expired yesterday.
Your ticket expired 2 days ago.
Your ticket expired 3 days ago.
Your ticket expired 4 days ago.
Your ticket expired 5 days ago.
15:33:14 Temp$ cat exp.rb
(0…5).each do |nb_of_days|
sentence = 'Your ticket expired ’ <<
case nb_of_days
when 0: ‘today’
when 1: ‘yesterday’
else “#{nb_of_days} days ago”
end << ‘.’
puts sentence
end
15:33:19 Temp$
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.