3 ms·
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]
- haalcion3 10y agoRead: https://ruby-doc.org/core-2.3.0/doc/syntax/precedence_rdoc.html 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/ https://dorey.github.io/JavaScript-Equality-Table/unified/
- konart 10y agoWell, "and, or" are control flow operators, not boolean operators. I though most of the Rubyists learn this day one tbh.
- singularity2001 10y agoIs this style guide official? https://github.com/bbatsov/ruby-style-guide/commit/5920497452c1f6f604742a735f5684e86d4c0003 https://github.com/bbatsov/ruby-style-guide/commit/592049745...