From owner-freebsd-ruby@FreeBSD.ORG Sat Jan 2 18:39:04 2010 Return-Path: Delivered-To: ruby@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AAA541065676 for ; Sat, 2 Jan 2010 18:39:04 +0000 (UTC) (envelope-from knu@iDaemons.org) Received: from mail.musha.org (v055125.ppp.asahi-net.or.jp [124.155.55.125]) by mx1.freebsd.org (Postfix) with ESMTP id 482228FC08 for ; Sat, 2 Jan 2010 18:39:04 +0000 (UTC) Received: from daemon.musha.org (daemon.local.idaemons.org [192.168.11.11]) by mail.musha.org (Postfix) with ESMTP id 6A6AF93CFB; Sun, 3 Jan 2010 03:22:36 +0900 (JST) Date: Sun, 03 Jan 2010 03:22:36 +0900 Message-ID: <86my0w2wpf.knu@iDaemons.org> From: "Akinori MUSHA" To: James Harrison In-Reply-To: <70626630-CEF2-40DA-853E-82FBE5CB9487@gmail.com> References: <70626630-CEF2-40DA-853E-82FBE5CB9487@gmail.com> Organization: Associated I. Daemons X-PGP-Public-Key: finger knu@FreeBSD.org X-PGP-Fingerprint: 081D 099C 1705 861D 4B70 B04A 920B EFC7 9FD9 E1EE MIME-Version: 1.0 (generated by EMIKO 1.14.1 - "Choanoflagellata") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Sun_Jan__3_03:22:36_2010-1"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Cc: ruby@freebsd.org Subject: Re: portupgrade code question X-BeenThere: freebsd-ruby@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD-specific Ruby discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jan 2010 18:39:04 -0000 --pgp-sign-Multipart_Sun_Jan__3_03:22:36_2010-1 Content-Type: text/plain; charset=US-ASCII 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/ --pgp-sign-Multipart_Sun_Jan__3_03:22:36_2010-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEABECAAYFAks/juwACgkQkgvvx5/Z4e668QCeNbuc6AbeEVo/ResbP/64az30 N+MAoITZyI4x/rgaAd9u8QvH4sZbRncN =XmQQ -----END PGP SIGNATURE----- --pgp-sign-Multipart_Sun_Jan__3_03:22:36_2010-1--