class SassC::Script::Value::List

def self.assert_valid_index(list, n)

Parameters:
  • n (Sass::Script::Value::Number) -- The index being checked.
  • list (Sass::Script::Value::List) -- The list for which the index should be checked.

Other tags:
    Private: -
def self.assert_valid_index(list, n)
  if !n.int? || n.to_i == 0
    raise ArgumentError.new("List index #{n} must be a non-zero integer")
  elsif list.to_a.size == 0
    raise ArgumentError.new("List index is #{n} but list has no items")
  elsif n.to_i.abs > (size = list.to_a.size)
    raise ArgumentError.new(
      "List index is #{n} but list is only #{size} item#{'s' if size != 1} long")
  end
end