Skip to content

Commit

Permalink
[0] is faster than .first
Browse files Browse the repository at this point in the history
  • Loading branch information
janlelis committed Dec 23, 2016
1 parent 9a49d9f commit e832ff9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/paint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class << self
# Takes a string and color options and colorizes the string, fast version without nesting
def [](string, *options)
return string.to_s if @mode.zero? || options.empty?
options = options.first if options.size == 1 && !options.first.respond_to?(:to_ary)
options = options[0] if options.size == 1 && !options[0].respond_to?(:to_ary)
@cache[options] + string.to_s + NOTHING
end

Expand All @@ -19,7 +19,7 @@ def %(paint_arguments, clear_color = NOTHING)
string, *options = paint_arguments
return string.to_s if options.empty?
substitutions = options.pop if options[-1].is_a?(Hash)
options = options.first if options.size == 1 && !options.first.respond_to?(:to_ary)
options = options[0] if options.size == 1 && !options[0].respond_to?(:to_ary)
current_color = @cache[options]

# Substitutions & Nesting
Expand Down

0 comments on commit e832ff9

Please sign in to comment.