Class: WithEase::Iterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/with_ease/iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#advancerObject (readonly)

Returns the value of attribute advancer.



7
8
9
# File 'lib/with_ease/iterator.rb', line 7

def advancer
  @advancer
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/with_ease/iterator.rb', line 7

def value
  @value
end

Instance Method Details

#drop(n = 1) ⇒ Object



9
10
11
12
13
14
# File 'lib/with_ease/iterator.rb', line 9

def drop(n=1) 
  n.times do
    @value = @advancer.(value)
  end
  self
end

#drop_fnObject



15
# File 'lib/with_ease/iterator.rb', line 15

def drop_fn = -> (n=1) { drop n }

#eachObject



18
19
20
21
22
23
# File 'lib/with_ease/iterator.rb', line 18

def each
  loop do
    yield value
    drop
  end
end

#take_fnObject



24
# File 'lib/with_ease/iterator.rb', line 24

def take_fn = -> (n) { take n }