--aVD9QWMuhilNxW9f
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Mar 24, 2011 at 06:58:36AM +0900, Jeremy Bopp wrote:
> 
> Equivalent from your example:
> 
> animal = "cat"
> puts animal == "cat" ? "yes" : "no"

That's not strictly equivalent.  The original PHP version didn't have any
newlines in the output.


> 
> /Really/ all 1 line:
> 
> animal = "cat"; puts animal == "cat" ? "yes" : "no"

Really *really* really all one line:

    puts (animal = 'cat') == 'cat' ? 'yes' : 'no'

Both PHP and Ruby return the value assigned from an assignment
expression.  Of course, assuming the assignment will necessarily be
paired directly with the ternary operation is kind of silly.  If you
really want an assignment and a return value of yes, given that as
written this basically guarantees that will always happen, you could
shorten it and clarify what is actually going on thusly:

    puts animal = 'cat' && 'yes'

. . . or:

    animal = 'cat' && (puts 'yes')

. . . but I think I'm getting way off the original point, now.

Apologies to readers for the extent to which I'm repeating things you
already know.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

--aVD9QWMuhilNxW9f
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iEYEARECAAYFAk2KfYIACgkQ9mn/Pj01uKVTHwCg6um3ryvLLcLD5bBZcOiGOO3S
HccAn3cbSnS1rWGq5hQQ4ujzb68xLRsA
ZM
-----END PGP SIGNATURE-----

--aVD9QWMuhilNxW9f--