module EnumerableWithScanLeft
Optional refinement which refines Enumerable
to add a #scan_left
method, in order to provide a more natural syntax in comparison to explicitly creating instances of the ScanLeft
class.
Without using this refinement, we wrap Enumerables in ScanLeft
instances:
ScanLeft.new([1,2,3]).scan_left(0, &:+) # => [0, 1, 3, 6]
Using this refinement, we can call #scan_left
directly on any Enumerable:
[1,2,3].scan_left(0, &:+) # => [0, 1, 3, 6]
@example
class Foo using EnumerableWithScanLeft def bar(x) [1,2,3].scan_left(x, &:+) end end Foo.new.bar(10) # => [10, 11, 13, 16]
Public Instance Methods
scan_left(initial, &block)
click to toggle source
# File lib/scan_left/enumerable_with_scan_left.rb, line 30 def scan_left(initial, &block) ScanLeft.new(self).scan_left(initial, &block) end