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?
- How is the AND/OR operator represented as in Regular Expressions?
- 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 ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- What does ‘&’ do in a C++ declaration?
- 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]
- 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?
- The difference between += and =+
- What is the ‘new’ keyword in JavaScript?
- Ruby: Can I write multi-line string with no concatenation?
- 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
- error: ‘ostream’ does not name a type
- What does the colon (:) operator do?
- Is there an exponent operator in C#?
- ActionController::UnknownFormat
- Array to Hash Ruby
- Multiple OR or AND conditions in IF statement
- How to map with index in Ruby?
- Understanding the result of modulo operator: %%
- Difference between `not` and `!` in ruby
- Reference — What does this symbol mean in PHP?
- warning: constant ::Fixnum is deprecated When generating new model
- Rails 4 RoutingError: No Route Matches
- How to sum array of numbers in Ruby?
- How to check if a value exists in an array in Ruby
- undefined method (NoMethodError) ruby
- How to uninstall ruby installed by ruby-install
- Rails syntax error : unexpected keyword_ensure, expecting end-of-input
- Removing all installed Gems and starting over
- Ruby `send` vs `call` method
- Is there a “not in” operator in JavaScript for checking object properties?
- Rails: I installed Ruby, now “bundle install” doesn’t work
- How to do a newline in output
- Determining type of an object in ruby
- What does @@variable mean in Ruby?
- Difference between rake db:migrate db:reset and db:schema:load
- What is the difference between a Process’ pid, ppid, uid, euid, gid and egid?
- Difference between map and collect in Ruby?
- Rails button_to vs. HTML Button Tag
- Creating and iterating a 2d array in Ruby
- Java Not Greater than Or Equal to Operator for Char Type
- Uninstall old versions of Ruby gems
- What are the double colons (::) in R?
- Using OR operator in a jQuery if statement
- Gem installation error: You have to install development tools first
- OCaml mod function returns different result compared with %
- An error occurred while installing json (1.8.1), and Bundler cannot continue – Rails
- Nginx error: client intended to send too large body
- How can I delete one element from an array by value
- What are those pipe symbols for in Ruby?
- How do I parse JSON with Ruby on Rails? [duplicate]
- ERROR: While executing gem … (Gem::FilePermissionError)
- No such file or directory @ rb_sysopen ruby
- The tilde operator in C
- Ruby ‘require’ error: cannot load such file
- How to convert a string to lower or upper case in Ruby
- Prolog “or” operator, query
- No implicit conversion of String into Integer (TypeError)?
- Multi-Line Comments in Ruby?