Sha256: db3c61421d8fb4e9862f88631d76507cac59c739196cf97278cff8238da5c5b4
Contents?: true
Size: 717 Bytes
Versions: 3
Compression:
Stored size: 717 Bytes
Contents
# frozen_string_literal: true module RaaP class Sized def initialize(&block) raise LocalJumpError, "no block given" unless block @block = block @such_that = nil end def pick(size:) such_that_loop do |skip| @block.call(size + skip) end end def such_that(&block) @such_that = block self end alias when such_that private def such_that_loop skip = 0 while skip < 100 picked = yield(skip) such_that = @such_that return picked if such_that.nil? || such_that.call(picked) skip += 1 raise "too many skips" unless skip < 100 end raise "never reached" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
raap-0.3.0 | lib/raap/sized.rb |
raap-0.2.0 | lib/raap/sized.rb |
raap-0.1.0 | lib/raap/sized.rb |