Method: Col::Formatter#check_correct_number_of_arguments

Defined in:
lib/col.rb

#check_correct_number_of_arguments(strings, *spec) ⇒ Object

In general, there should be the same number of arguments as there are strings:

Col["one"].fmt( :b )
Col["one", "two"].fmt( [:red, :on_white], [:bold, :negative] )
Col["one", "two", "three"].fmt( :yellow, [:green, :bold], :italic )
Col["one", "two", "three", "four"].fmt(:rb, :y, :cb, :m)
Col["one", "two", "three", "four"].fmt "rb,y,cb,m"

As a special case, if there is only one string, it can have any number of arguments:

Col["string"].fmt( :yellow, :bold, :italic, :blink, :negative, :on_magenta )

If the number of arguments is incorrect, a Col::Error is thrown.



135
136
137
138
139
140
141
142
143
# File 'lib/col.rb', line 135

def check_correct_number_of_arguments(strings, *spec)
  nargs = spec.size
  if nargs == 1 and spec.first.is_a? String
    nargs = spec.first.split(/,/).size
  end
  if strings.size > 1 and nargs != strings.size
    raise Col::Error, "incorrect number of arguments: #{render(spec)}"
  end
end