Created
May 31, 2017 08:47
-
-
Save swanandp/e987f388fd9ef69d6c58bd1a1a314480 to your computer and use it in GitHub Desktop.
Ruby's &. operator is deceptive. It doesn't behave the same at foo && foo.something when foo is false.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):004:0> false&.foo | |
NoMethodError: undefined method `foo' for false:FalseClass | |
from (irb):4 | |
from /Users/swanand/.rbenv/versions/2.3.1/bin/irb:11:in `<main>' | |
irb(main):005:0> false && false.foo | |
=> false | |
irb(main):006:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment