Skip to content

Instantly share code, notes, and snippets.

@nekoTheShadow
Last active August 29, 2015 14:12
Show Gist options
  • Save nekoTheShadow/c8861aa6d8be466b86c2 to your computer and use it in GitHub Desktop.
Save nekoTheShadow/c8861aa6d8be466b86c2 to your computer and use it in GitHub Desktop.
# Here your code !
module FibSupport
def idx2fib(idx, a=1, b=0)
idx == 1 ? a : idx2fib(idx-1,a+b,a)
end
end
class Fib
include FibSupport
def initialize(n=nil)
@n = n
@range = (@n == nil) ? (1..Float::INFINITY) : (1..@n)
end
def all
@n != nil ? @range.map{|idx| idx2fib(idx)} : nil
end
def at(i)
@range.include?(i) ? idx2fib(i) : nil
end
end
fib = Fib.new(10)
p fib.all
p fib.at(3)
p fib.at(11)
fib2 = Fib.new
p fib2.all
p fib2.at(100)
@nekoTheShadow
Copy link
Author

paizaIOとの連携テスト。あとコメント投稿もテスト。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment