Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created June 13, 2014 20:15
Show Gist options
  • Save jgaskins/3b42b05864f0246eb58f to your computer and use it in GitHub Desktop.
Save jgaskins/3b42b05864f0246eb58f to your computer and use it in GitHub Desktop.
Short-circuiting OR/AND in Ruby, represented as methods
# If it were possible to override && and || in Ruby, this is how it might look.
class NilClass
def && other
self
end
def || other
other
end
end
class FalseClass
def && other
self
end
def || other
other
end
end
class BasicObject
def && other
other
end
def || other
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment