+ 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?
2 odpowiedzi
+ 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
- 1
Hi to everyone