Last active
September 9, 2016 14:48
-
-
Save iamvery/4692735 to your computer and use it in GitHub Desktop.
Check to see if an array includes any part of the given search value.
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
# %w(abd def ghi).fuzzy_include? 'definition' # => true | |
class Array | |
def fuzzy_include?(search_value, regex_format = '%s') | |
inject(false) do |is_found, array_value| | |
is_found or !!(search_value =~ /#{regex_format % array_value}/) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment