Skip to content

Instantly share code, notes, and snippets.

@brianmcallister
Last active December 9, 2015 22:59
Show Gist options
  • Save brianmcallister/4341575 to your computer and use it in GitHub Desktop.
Save brianmcallister/4341575 to your computer and use it in GitHub Desktop.
Wrapper around Ruby's Array#index method.
# Wrapper around Ruby's Array#index method.
# https://gist.github.com/brianmcallister/4341575
#
# value - The value in the list to search for.
# list - The list to search through.
#
# Examples
#
# $list: a b c;
# @debug location(b, $list);
# # => 2
#
# Returns The index of the value in the list, or false if nothing is found.
def location(value, list)
assert_type list, :List
index = list.value.index(value)
if index.nil?
Sass::Script::Bool.new(false)
else
Sass::Script::Number.new(index + 1)
end
end
declare :location, [:value, :list]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment