Skip to content

Instantly share code, notes, and snippets.

@iamvery
Last active September 9, 2016 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamvery/4692735 to your computer and use it in GitHub Desktop.
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.
# %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