Class: TableUtils::LimitLoops
- Inherits:
-
Object
- Object
- TableUtils::LimitLoops
- Defined in:
- lib/table_utils/limit_loops.rb
Instance Attribute Summary collapse
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize(max_count) ⇒ LimitLoops
constructor
A new instance of LimitLoops.
- #limit ⇒ Object
Constructor Details
#initialize(max_count) ⇒ LimitLoops
Returns a new instance of LimitLoops.
5 6 7 |
# File 'lib/table_utils/limit_loops.rb', line 5 def initialize max_count @total = @left_count = max_count end |
Instance Attribute Details
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/table_utils/limit_loops.rb', line 3 def total @total end |
Class Method Details
.to(max_count, &block) ⇒ Object
17 18 19 |
# File 'lib/table_utils/limit_loops.rb', line 17 def self.to max_count, &block LimitLoops.new(max_count).limit &block end |
Instance Method Details
#check! ⇒ Object
13 14 15 |
# File 'lib/table_utils/limit_loops.rb', line 13 def check! throw self if @left_count and (@left_count -= 1) <= 0 end |
#limit ⇒ Object
9 10 11 |
# File 'lib/table_utils/limit_loops.rb', line 9 def limit catch(self) { yield self } end |