• Cursos
  • Compilador de Código
  • Discutir
  • Preços
  • Teams
Menu
+ 5

Ruby - A strange boolean operator

Given this code: int = 0 str = "" if int && str then puts 1 else puts 0 end why does it output 1, that is, why the "and" is true?

booleansruby
31st May 2019, 10:30 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Respostas
+ 4
Both 0 and "" are truthy in Ruby. https://gist.github.com/jfarmer/2647362 https://stackoverflow.com/questions/15989329/what-is-good-if-an-empty-string-is-truthy
31st May 2019, 11:55 AM
Anna
Anna - avatar
- 1
Hi to everyone
2nd Jun 2019, 7:03 AM
Promise

Costuma ter perguntas como essa?

Aprenda de maneira mais eficiente, de graça:

  • Introdução ao Python

    7.1M de alunos

  • Introdução ao Java

    4.7M de alunos

  • Introdução ao C

    1.5M alunos

  • Introdução ao HTML

    7.5M alunos

Ver todos os cursos
Quente hoje
Ошибка в приложении Sololearn
1 Votes
Is anyone else experiencing this Sololearn issue?
0 Votes
NEO V2.0
1 Votes
Sololearn course
1 Votes
solo learn program issue - iPhone?
1 Votes
Is it possible to write Rust code that is as compact and expressive as Python?
0 Votes
Bug sur le deuxième cours de python
1 Votes
Best language?
0 Votes
I am learning javascript intrmdt but when I play a code challenge. The app is givin me comlecated questions with less time.why?
0 Votes
Learn - multiple choice course questions display in one box making it impossible to continue
1 Votes