Skip to content

Instantly share code, notes, and snippets.

@TwP
Created February 11, 2009 04:09
Show Gist options
  • Save TwP/61819 to your computer and use it in GitHub Desktop.
Save TwP/61819 to your computer and use it in GitHub Desktop.
# LAME
if a > b
foo = a
else
foo = b
end
# SWEET
foo = if a > b
a
else
b
end
# SWEETER
foo = a > b ? a : b
# WTF?
foo = [a,b].max
# -------------------------------------------------
# LAME
def method
begin
# do stuff
rescue
# handle the error
ensure
# always do this
end
end
# SWEET
def method
# do stuff
rescue
# handle the error
ensure
# always do this
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment