module Proxinacci

Public Instance Methods

closest_fibonacci() click to toggle source
# File lib/proxinacci.rb, line 2
def closest_fibonacci
  # Don't allow any zero or negative values
  return nil if self <= 0
  
  x, y = 0, 1
  while y < self
    # Progress through the Fibonacci sequence while y is less
    # than the number calling the method
    x, y = y, x + y
  end
  
  # At this point x is the largest Fibonacci number smaller than the
  # number calling the method
  return x
end