portupgrade code question

Akinori MUSHA knu at iDaemons.org
Sat Jan 2 18:39:04 UTC 2010


At Fri, 1 Jan 2010 20:11:52 -0700,
James Harrison wrote:
> I've been reading the code for portupgrade and have come across something I don't understand at all.
>
> In the lib/portsdb.rb, the glob method starts on line 757.
>
> On line 773, as part of the glob method, we have the following:
>
> <---snip--->
>         # shortcut
>         if portinfo = port(pattern)
>           if block_given?
>             yield(portinfo)
>             return nil
>           else
>             return [portinfo]
>           end
>         end
>       end
> <---/snip--->
>
> Won't the condition "if portinfo = port(pattern)" always evaluate to true, as it's an assignation not a test? Is it meant to read if portinfo == port(pattern)?

What made you think port(pattern) always evaluates to true?  Whenever
a given pattern does not match anything port() returns a false value
(nil).

When a given pattern represents an exact port there is no need to
perform further pattern matching.  That is the intention, a
"shortcut".

--
Akinori MUSHA / http://akinori.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ruby/attachments/20100102/768e48b5/attachment.pgp


More information about the freebsd-ruby mailing list