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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 8, 2007, at 9:20 AM, Mark Veerman wrote:> 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, > MarkWell, 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Feb-08 15:57 UTC
Re: shortcut for ternary operation in views
Hi -- On Thu, 8 Feb 2007, Rob Biedenharn wrote:> > On Feb 8, 2007, at 9:20 AM, Mark Veerman wrote: >> 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 > > 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.<%= %> 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) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---