Last active
December 9, 2015 22:59
-
-
Save brianmcallister/4341575 to your computer and use it in GitHub Desktop.
Wrapper around Ruby's Array#index method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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