• Kurse
  • Code Compiler
  • Diskutieren
  • Preise
  • 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 Antworten
+ 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

Häufig solche Fragen?

Effizienter lernen, kostenlos:

  • Einführung in Python

    7.1M Lernende

  • Einführung in Java

    4.7M Lernende

  • Einführung in C

    1.5M Lernende

  • Einführung in HTML

    7.5M Lernende

Alle Kurse anzeigen
Heute heiß
I have finished first in Saturn League 3 times in a row, why have I not been given the badge for “Intergalactic Champion”
1 Votes
Solving coding challenges
2 Votes
I am new
1 Votes
Changing String Variables into int in C++
0 Votes
Advertising in Sololearn
1 Votes
Fill in the blank to declare a static variable.
0 Votes
RUST'S FUTURE
1 Votes
Question #2: "Please activate your account and keep learning to enable messaging. An email has been sent to you"
1 Votes
Programming Language
0 Votes
What are the advantages and disadvantages of using let vs var when declaring variables in JavaScript?
0 Votes