Ruby coding question


#1

I have a question about ruby code delimiters.

This code block:

<% end -%>

What does the “-” before the ending delimiter signify? My code errored
out, I thought those were
misprints or something in the book, but added them and it works. I don’t
recall seeing that in the
Ruby appendix, and I’ve never seen this convention before (like with JSP
or ASP).

TIA

Tom


#2

Hi,

Tom Dell’Aringa wrote:

<% end -%>

What does the “-” before the ending delimiter signify? My code errored out, I thought those were
misprints or something in the book, but added them and it works. I don’t recall seeing that in the
Ruby appendix, and I’ve never seen this convention before (like with JSP or ASP).

Simply prunes the \n after ‘end’.


#3

— Jean-Christophe M. removed_email_address@domain.invalid wrote:

Simply prunes the \n after ‘end’.

Thanks - Had I literally read the next line… :confused: I would have known
that. Nice feature though!

Tom


#4

Tom:

the final -%> differs from %> in that if there is no text produced
between the delimiters then it takes no space on the page. I believe
the standard delimiter %> would take up some space whether or not it
needed to. A good example of when this may be useful (I used it the
other day) is if you were making invoices and had something like

<% org.company_name %> #no need for fancy delimiter as all
companies will have names
<% org.address1 %> #as above
<% org.address2 -%> #note fancy delimiter because many
companies don’t have an address2 and we don’t want a blank line
appearing in the address.

bruce