Shortcut for ternary operation in views

Hi,

I attended a recent Rails Edge conference and seem to recall a new
built-in
shortcut to the following, frequently used, code:
<%= foo.nil? ? ‘’ : foo %>

Does anyone know what that might be?

Thanks,
Mark

On Feb 8, 2007, at 9:20 AM, Mark Veerman wrote:

Mark
Well, it’s nothing new:

<%= “#{foo}” %>

Since nil.to_s is an empty string and string interpolation does a .to_s

<%= foo.to_s %>

also works.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Hi –

On Thu, 8 Feb 2007, Rob B. wrote:

also works.

<%= %> does a to_s too, so:

<%= foo %>

should be OK.

David


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)