Skip to content

Instantly share code, notes, and snippets.

@swanandp
Created May 31, 2017 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swanandp/e987f388fd9ef69d6c58bd1a1a314480 to your computer and use it in GitHub Desktop.
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.
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