News for hackers. Stuff that matters.

So you think you know Ruby

Computer science 101: what is the value of x,y,z after these calculations:

x = true and false

y = 1 && 0 || 1

z = ( true or true and false )

Before typing this in your ruby irb console, please answer in your head what you honestly think the answer should be.

spoiler: [x,y,z] => [true, 0, false]

( 3 comments | on HN )
Re:So you think you know Ruby by haalcion3 on Monday October 17, 2016 @06:49AM (#12723934)
Read:

https://ruby-doc.org/core-2.3.0/doc/syntax/precedence_rdoc.h...

Live it. Love it. It's not that hard.

It's certainly easier than the following (granted that it isn't an order of ops thing, but it's much more convoluted):

https://dorey.github.io/JavaScript-Equality-Table/unified/

Re:So you think you know Ruby by konart on Monday October 17, 2016 @06:49AM (#12723935)
Well, "and, or" are control flow operators, not boolean operators. I though most of the Rubyists learn this day one tbh.
Re:So you think you know Ruby by singularity2001 on Monday October 17, 2016 @06:53AM (#12723950)