Module: ConvenientService::Support::FiniteLoop
- Included in:
- Utils::Module::GetOwnInstanceMethod
- Defined in:
- lib/convenient_service/support/finite_loop.rb
Defined Under Namespace
Modules: Exceptions
Constant Summary collapse
- MAX_ITERATION_COUNT =
1_000
Class Method Summary collapse
-
.finite_loop(default: nil, max_iteration_count: MAX_ITERATION_COUNT, raise_on_exceedance: true, &block) ⇒ Object
Can be any type.
Class Method Details
.finite_loop(default: nil, max_iteration_count: MAX_ITERATION_COUNT, raise_on_exceedance: true, &block) ⇒ Object
Returns Can be any type.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/convenient_service/support/finite_loop.rb', line 74 def finite_loop(default: nil, max_iteration_count: MAX_ITERATION_COUNT, raise_on_exceedance: true, &block) ::ConvenientService.raise Exceptions::NoBlockGiven.new unless block loop.with_index do |_, index| if index >= max_iteration_count break default unless raise_on_exceedance ::ConvenientService.raise Exceptions::MaxIterationCountExceeded.new(limit: max_iteration_count) end yield(index) end end |