It’s a matter of operator precedence.
||
has a higher precedence than or
.
So, in between the two you have other operators including ternary (? :
) and assignment (=
) so which one you choose can affect the outcome of statements.
Here’s a ruby operator precedence table.
See this question for another example using and
/&&
.
Also, be aware of some nasty things that could happen:
a = false || true #=> true a #=> true a = false or true #=> true a #=> false
Both of the previous two statements evaluate to true
, but the second sets a
to false
since =
precedence is lower than ||
but higher than or
.
Related Posts:
- Difference between “and” and && in Ruby?
- What exactly does += do in python?
- Use of “instanceof” in Java [duplicate]
- What are XAND and XOR
- ^=, -= and += symbols in Python
- What does the question mark character (‘?’) mean in C++?
- proper name for python * operator?
- What does the question mark character (‘?’) mean in C++?
- What does the percentage sign mean in Python
- Not equal to != and !== in PHP
- What does the percentage sign mean in Python
- ruby operator “=~” [duplicate]
- What does << mean in Ruby?
- What does =~ do in Perl?
- What does ||= (or-equals) mean in Ruby?
- What does “+=” (plus equals) mean?
- Does Python have a ternary conditional operator?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- How is the AND/OR operator represented as in Regular Expressions?
- Behaviour of increment and decrement operators in Python
- Is there a “not equal” operator in Python?
- What is the result of % in Python?
- Does Python have a ternary conditional operator?
- Is there a “not equal” operator in Python?
- Get underlined text with Markdown
- What does the “+=” operator do in Java?
- What does the ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- What is the meaning of *nix?
- What does operator “dot” (.) mean?
- What does ‘&’ do in a C++ declaration?
- Get underlined text with Markdown
- Creating a “logical exclusive or” operator in Java
- What does “|=” mean? (pipe equal operator)
- What are bitwise shift (bit-shift) operators and how do they work?
- assignment operator overloading in c++
- How to use operator ‘-replace’ in PowerShell to replace strings of texts with special characters and replace successfully
- Error: “expression must have integral or unscoped enum type” [duplicate]
- Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000?
- PowerShell and the -contains operator
- What does the “map” method do in Ruby?
- Logical XOR operator in C++?
- Regex how to match an optional character
- proper name for python * operator?
- What does the power operator (**) in python translate into?
- Difference between the == and %in% operators in R
- How to write a switch statement in Ruby
- what is the meaning of == sign?
- The difference between += and =+
- Parsing a JSON string in Ruby
- Tell Ruby Program to Wait some amount of time
- Rails 5 ActionController::InvalidAuthenticityToken error
- PowerShell and the -contains operator
- What is the ‘new’ keyword in JavaScript?
- what does ? ? mean in ruby
- Ruby: Can I write multi-line string with no concatenation?
- Regex how to match an optional character
- Reference — What does this symbol mean in PHP?
- What does question mark and dot operator ?. mean in C# 6.0?
- How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?
- Why use Ruby’s attr_accessor, attr_reader and attr_writer?
- What is the idiomatic Go equivalent of C’s ternary operator?
- What does %w(array) mean?
- The tilde operator in Python
- How to update Ruby with Homebrew?
- How to use “gets” and “gets.chomp” in Ruby
- Getting a substring in Ruby by x number of chars
- What does `<>` mean in Python?
- How to check whether a string contains a substring in Ruby
- What is ‘\0’ in C++?
- What is a Question Mark “?” and Colon “:” Operator Used for?
- Ruby: How to install a specific version of a ruby gem?
- class << self idiom in Ruby
- What is the difference between ‘/’ and ‘//’ when used for division?
- Unable to install gem – Failed to build gem native extension – cannot load such file — mkmf (LoadError)
- error: ‘ostream’ does not name a type
- What does the colon (:) operator do?
- Is there an exponent operator in C#?
- What is attr_accessor in Ruby?
- ActionController::UnknownFormat
- How to read lines of a file in Ruby
- Array to Hash Ruby
- Multiple OR or AND conditions in IF statement
- Cannot load such file — bcrypt_ext
- How do I remove Permission denied @ rb_sysopen – Gem install error?
- Ruby: undefined method `[]’ for nil:NilClass when trying to get Enumerator on an Array of Hashes
- How to map with index in Ruby?
- Understanding the result of modulo operator: %%
- Difference between `not` and `!` in ruby
- Is there a difference between x++ and ++x in java?
- Reference — What does this symbol mean in PHP?
- warning: constant ::Fixnum is deprecated When generating new model
- R: += (plus equals) and ++ (plus plus) equivalent from c++/c#/java, etc.?
- Ruby equivalent for Python’s “try”?
- Rails 4 RoutingError: No Route Matches
- How to sum array of numbers in Ruby?
- Ruby array to string conversion
- Javascript: operator overloading
- How to check if a value exists in an array in Ruby