Forum: Ruby on Rails Ruby coding question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
77236cb3ef11b54bd21026de39e4050d?d=identicon&s=25 pixelmech (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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


http://www.pixelmech.com/
Eb96620826312516bb4a2d6deeee6688?d=identicon&s=25 jc.michel (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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'.
Re:
77236cb3ef11b54bd21026de39e4050d?d=identicon&s=25 pixelmech (Guest)
on 2005-11-12 12:49
(Received via mailing list)
--- Jean-Christophe Michel <jc.michel@symetrie.com> wrote:

> Simply prunes the \n after 'end'.

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

Tom



http://www.pixelmech.com/
2dd904ec5981c31e7bb7a5743a53caf8?d=identicon&s=25 brucebalmer (Guest)
on 2005-11-24 14:57
(Received via mailing list)
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
This topic is locked and can not be replied to.