Issue #15768 has been updated by zverok (Victor Shepelev).


It is a conscient (though controversial according to some) design decision, borrowed from Perl.

`&&` and `and` are NOT synonyms. `&&`/`||` are boolean operators, while `and`/`or` are control-flow operators.
Demonstrated behavior is useful in statements ending with `(and|or) (exit|return|raise)`:
```ruby
foo = some_value || other_value && third_value or raise "No branch have produced really good value"

this && that || something and return "All branches produced some undesirable result"
```
That's why those operators have the lowest possible precedence -- to be performed definitely AFTER the rest of the statement.

I really like this feature, but should also say that confusion about `&&` vs `and` is so high, that they are banned explicitly by Bozhidar Batsov's "Ruby Style Guide" (for context: [very heated discussion](https://github.com/rubocop-hq/ruby-style-guide/pull/730)), and even *half of the standard library* uses `and` and `or` in boolean context.



----------------------------------------
Bug #15768: "and", &&, boolean issue, different ruby versions, confusing
https://bugs.ruby-lang.org/issues/15768#change-77629

* Author: daBee (da Bee)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Just caught this:

``` ruby
# version 2.5.1, Mac OS

v1 = true and false                                # => IRB: true
p v1			                        		# => app.rb: true, IRB: false
v2 = true && false                                 # => IRB: false
p v2					                       # => app.rb: false, IRB: false
puts 1 > -1 && 257 < 256			# => app.rb: false, IRB: false

```

## IRB Mac OS 2.6.2

``` ruby
>> v1 = true and false
=> false
>> v2 = true && false
=> false
>> puts v1
true
=> nil
>> puts v2
false
=> nil
```

I might be missing something, but I think there's an issue here, on both versions 2.5.1 and 2.6.2.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>