Last active
December 18, 2015 20:59
-
-
Save enil/5844368 to your computer and use it in GitHub Desktop.
A recursive method to return the last parameter, Haskell-style.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def last(first=nil, *rest) | |
if rest.empty? | |
first | |
else | |
last(*rest) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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