Skip to content

Instantly share code, notes, and snippets.

@kzar
Created January 5, 2012 12:39
Show Gist options
  • Select an option

  • Save kzar/1565088 to your computer and use it in GitHub Desktop.

Select an option

Save kzar/1565088 to your computer and use it in GitHub Desktop.
Ruby &&= operator
ruby-1.9.2-p0 :001 > a = nil
=> nil
ruby-1.9.2-p0 :002 > a = (a and nil)
=> nil
ruby-1.9.2-p0 :003 > a = nil
=> nil
ruby-1.9.2-p0 :004 > a = (a and 1)
=> nil
ruby-1.9.2-p0 :005 > a = 1
=> 1
ruby-1.9.2-p0 :006 > a = (a and nil)
=> nil
ruby-1.9.2-p0 :007 > a = 1
=> 1
ruby-1.9.2-p0 :008 > a = (a and 1)
=> 1
ruby-1.9.2-p0 :009 > a = nil
=> nil
ruby-1.9.2-p0 :010 > a &&= nil
=> nil
ruby-1.9.2-p0 :011 > a = nil
=> nil
ruby-1.9.2-p0 :012 > a &&= 1
=> nil
ruby-1.9.2-p0 :013 > a = 1
=> 1
ruby-1.9.2-p0 :014 > a &&= nil
=> nil
ruby-1.9.2-p0 :015 > a = 1
=> 1
ruby-1.9.2-p0 :016 > a &&= 1
=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment