Created
February 9, 2015 19:47
-
-
Save jamesmartin/129ebd5e99b264f7f2f8 to your computer and use it in GitHub Desktop.
Select from a list of values where arbitrary conditions are met
This file contains hidden or 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
| def has_foo? | |
| ->(thing) { thing == "foo" } | |
| end | |
| def has_bar? | |
| ->(thing) { thing == "bar" } | |
| end | |
| def has_baz? | |
| ->(thing) { thing == "baz" } | |
| end | |
| if __FILE__ == $0 | |
| conditions = [has_foo?, has_bar?, has_baz?] | |
| result = ["foo", "baz", "uq_", "bar"].select do |thing| | |
| conditions.any? { |condition| condition.call(thing) } | |
| end | |
| puts result | |
| end |
Author
jamesmartin
commented
Feb 9, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment