Skip to content

Instantly share code, notes, and snippets.

@colinrymer
Last active December 17, 2015 10:39
Show Gist options
  • Save colinrymer/5596687 to your computer and use it in GitHub Desktop.
Save colinrymer/5596687 to your computer and use it in GitHub Desktop.

When I first saw this #asset_allowed? method, I knew there was a nice collection method I could use to clean this up, but couldn't remember and forgot to check the Enumerable module. Stumbled upon the #any? method while looking at a nice git pre-commit hook in Ruby and thought, "Bingo!".

def asset_allowed?(asset)
  self.logical_asset_filter.reduce(false) do |accum, matcher|
    accum || (matcher =~ asset)
  end ? true : false
end
def asset_allowed?(asset)
  self.logical_asset_filter.any? { |matcher| matcher =~ asset }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment