Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 13, 2012 23:55
Show Gist options
  • Save perspectivezoom/2927212 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2927212 to your computer and use it in GitHub Desktop.
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