From: Christian Boos Date: 2006-02-03T19:30:08+09:00 Subject: Re: ruby-dev summary 28206-28273 ara.t.howard@noaa.gov wrote: > On Thu, 2 Feb 2006, Minero Aoki wrote: > >> [ruby-dev:28217] ANDCALL operator >> >> Nobuyoshi Nakada suggested a new operator `&?' (this notation is >> temporary) >> which evaluates left-hand-side expression, and if it is true then call >> right-hand-side method. For example: >> >> if a[1] and a[1].strip.empty? >> || >> if a[1] &? strip.empty? >> >> h["key"] and h["key"].dispatch >> || >> h["key"] &? dispatch >> >> The motivation of this operator is to avoid duplication of expression. I usually write those as: if (elt = a[1]) and elt.strip.empty? and (k = h["key"]) and k.dispatch ... assuming it costs nothing to create a new temporary variable. But if Nobu's idea catches on, I'd rather suggest extending the syntax to allow for conditional method call (using .?), as I find the above notation (&?) too confusing. -- Christian