Skip to content

Instantly share code, notes, and snippets.

@theqabalist
Last active August 29, 2015 14:17
Show Gist options
  • Save theqabalist/dddbb3ee05a4b2feda13 to your computer and use it in GitHub Desktop.
Save theqabalist/dddbb3ee05a4b2feda13 to your computer and use it in GitHub Desktop.
Example
TAGS = [
{ tags: [{ key: 'Purpose', value: 'pairing' }] },
{ tags: [{ key: 'Purpose', value: 'pairing' }, { key: 'Color', value: 'blue' }] }
]
def do_tags_exist(kvs)
lambda do |instance|
kvs.all? do |k, v|
instance[:tags].any? { |tag| tag[:key] == k.to_s && tag[:value] == v }
end
end
end
puts TAGS.select(&do_tags_exist(Purpose: 'pairing')).inspect
puts TAGS.select(&do_tags_exist(Purpose: 'pairing', Color: 'blue'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment