Class: Fibber
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/bin/math_server.rb
Overview
Holds state for a fibonacci series
Instance Method Summary collapse
- #generator ⇒ Object
-
#initialize(limit) ⇒ Fibber
constructor
A new instance of Fibber.
Constructor Details
#initialize(limit) ⇒ Fibber
Returns a new instance of Fibber.
50 51 52 53 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/bin/math_server.rb', line 50 def initialize(limit) fail "bad limit: got #{limit}, want limit > 0" if limit < 1 @limit = limit end |
Instance Method Details
#generator ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/grpc-1.50.0-x86_64-linux/src/ruby/bin/math_server.rb', line 55 def generator return enum_for(:generator) unless block_given? idx, current, previous = 0, 1, 1 until idx == @limit if idx.zero? || idx == 1 yield Math::Num.new(num: 1) idx += 1 next end tmp = current current = previous + current previous = tmp yield Math::Num.new(num: current) idx += 1 end end |