Skip to content

Instantly share code, notes, and snippets.

@pokk
Created August 1, 2017 02:44
Show Gist options
  • Save pokk/e33b104e86a3495f65ca05fe47e4121b to your computer and use it in GitHub Desktop.
Save pokk/e33b104e86a3495f65ca05fe47e4121b to your computer and use it in GitHub Desktop.
What is `&&=` and `||=` meaning in ruby?

Introduction

Always I confuse &&= and ||=, what's difference between them?

Magic

operation &&=

a &&= b

a = a && b

a = b if a

Those of three are equivalent.

operation ||=

a ||= b

a = a || b

a = b unless a

Thoise of three are equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment