# Author # David on #{Date.today.strftime("%m/%d/%y")}=>
# Author # David on #{Date.today.strftime("%m/%d/%y")}
However, when I read this template file into my test file, these strings appear as exactly the same as they appear in the template, as oppose to showing today date. So I searched on the Internet and find that Ruby treats single quotes and double quotes really differently: the double quotes interpret the interpolation and the escaped characters within the string, while single quotes do not do these two things. So performance-wise, using double quote is gonna take longer if interpolation or escaped character is involved.
Now back to my problem, the reason that the date is not shown correctly is that the content of the template is read as being wrapped with single quotes. So how can we tell Ruby that we want the content as to be wrapped with double quotes? We can use the double quote mark "%Q{}". Everything within the delimiter will appear as if they are wrapped with double quotes (see below).
%Q(# Author # David on #{Date.today.strftime("%m/%d/%y")})=>
# Author # David on 02/06/2013
No comments:
Post a Comment