Skip to content

Commit

Permalink
Simplify Sparkline#format
Browse files Browse the repository at this point in the history
* No need for arity checks
* Use `Enumerable#map`
  • Loading branch information
Peter Suschlik committed Feb 3, 2014
1 parent 067bcb4 commit 7f6ec7f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/sparkr/sparkline.rb
Expand Up @@ -46,16 +46,10 @@ def initialize(_numbers)
# # => "▁█" (colored, which you can't see)
#
# @return [Sparkline] itself
def format(&block)
new_ticks = []
@ticks.each_with_index do |tick, index|
if block.arity == 2
new_ticks << yield(tick, @original_numbers[index])
elsif block.arity == 3
new_ticks << yield(tick, @original_numbers[index], index)
end
def format
@ticks = @ticks.map.with_index do |tick, index|
yield tick, @original_numbers[index], index
end
@ticks = new_ticks
self
end

Expand Down

0 comments on commit 7f6ec7f

Please sign in to comment.