mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Remove code duplication in array and tuple_prefix
https://github.com/awesome-print/awesome_print/pull/246#issuecomment-238190911
This commit is contained in:
parent
fff7e50597
commit
1f07a679b8
1 changed files with 10 additions and 10 deletions
|
@ -54,11 +54,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def array_prefix(iteration, width)
|
def array_prefix(iteration, width)
|
||||||
if options[:index]
|
generic_prefix(iteration, width)
|
||||||
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
|
|
||||||
else
|
|
||||||
indent
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def methods_array
|
def methods_array
|
||||||
|
@ -99,11 +95,7 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def tuple_prefix(iteration, width)
|
def tuple_prefix(iteration, width)
|
||||||
if options[:index]
|
generic_prefix(iteration, width, ' ')
|
||||||
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
|
|
||||||
else
|
|
||||||
indent + ' '
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_tuple(name)
|
def generate_tuple(name)
|
||||||
|
@ -131,6 +123,14 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generic_prefix(iteration, width, padding='')
|
||||||
|
if options[:index]
|
||||||
|
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
|
||||||
|
else
|
||||||
|
indent + padding
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def width(items)
|
def width(items)
|
||||||
(items.size - 1).to_s.size
|
(items.size - 1).to_s.size
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue