A bit late, but I was reading this post again, but your code is
actually not the same, if I understood  you right.

because from is assigned "Unknown" if it's an empty string.
And from || "Unknown" results in true if from is defined, so the value
"Unknown" is not assigned to it. Right?


Krekna


2006/3/1, dblack / wobblini.net <dblack / wobblini.net>:
> Hi --
>
> On Thu, 2 Mar 2006, Krekna Mektek wrote:
>
> > Hi there,
> >
> > 2006/3/1, dblack / wobblini.net <dblack / wobblini.net>:
> >> Hi --
> >>
> >> On Thu, 2 Mar 2006, Krekna Mektek wrote:
> >>
> >>> AFAIC See, this works all right, but my question is, just to learn the
> >>> Ruby style, can this be done shorter (better)?
> >>>
> >>> class LineChecker
> >>>  def checkline(line)
> >>>      if line =~ /Checking:/
> >>>         line =~ /<(.*?)>.*<(.*)>/
> >>>         from = $1; rcpt = $2
> >>>         from = "Unknown" if from == ""
> >>>         rcpt = "Unknown" if rcpt == ""
> >>>         return ([from,rcpt])
> >>>      elsif line =~ /ClamAV-clamd\ result:\ /
> >>>        return $'
> >>>      else?
> >>>        return []?
> >>>      end
> >>>
> >>>  end
> >>> end
> >
> > This looks indeed beautiful. Hmm, let me see, I can't find the capture
> > method of the Regexp class in the language reference on rubycentral?
>
> It's newer than that language ref.
>
> > What does this one do?
> >
> >  [from || "Unknown", rcpt || "Unknown"]
> >
> > Does this mean that if from is empty, but defined, that it returns to
> > false, and then "Unknown" is chosen? Hah, neat!
>
> Actually an empty string is "true" in the Boolean sense, so this idiom
> depends on from and rcpt being nil -- which they will be, if the match
> fails.
>
>
> David
>
> --
> David A. Black (dblack / wobblini.net)
> Ruby Power and Light (http://www.rubypowerandlight.com)
>
> "Ruby for Rails" chapters now available
> from Manning Early Access Program! http://www.manning.com/books/black
>
>