Class: Humanized::Number::PartitionEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/humanized/interpolation/number.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(range, size) ⇒ PartitionEnumerator
constructor
A new instance of PartitionEnumerator.
Constructor Details
#initialize(range, size) ⇒ PartitionEnumerator
Returns a new instance of PartitionEnumerator.
27 28 29 30 |
# File 'lib/humanized/interpolation/number.rb', line 27 def initialize(range, size) @range = range @size = size end |
Instance Method Details
#each ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/humanized/interpolation/number.rb', line 31 def each i = @range.first size = @range.last - @range.first e = @range.end if @range.exclude_end? e = e - 1 else size = size + 1 end m = size.modulo(@size) if m != 0 yield(i...(i+m)) i = i+m end while( i <= e ) yield(i...(i+@size)) i = i+@size end end |