Created
June 13, 2012 23:55
-
-
Save perspectivezoom/2927212 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Numeric | |
def fibonacci() | |
if self < 0 | |
raise "Cannot Fibonacci a negative number" | |
elsif [0,1].include? self | |
self | |
else | |
ar = [0,1] | |
2.upto(self) do |n| | |
ar << ar[0] + ar[1] | |
ar = ar[1,2] | |
end | |
ar[1] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment