Skip to content

Instantly share code, notes, and snippets.

@enil
Last active December 18, 2015 20:59
Show Gist options
  • Save enil/5844368 to your computer and use it in GitHub Desktop.
Save enil/5844368 to your computer and use it in GitHub Desktop.
A recursive method to return the last parameter, Haskell-style.
def last(first=nil, *rest)
if rest.empty?
first
else
last(*rest)
end
end
def sum(first=0, *rest)
if rest.empty?
first
else
first + sum(*rest)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment