Skip to content

Instantly share code, notes, and snippets.

@xander-miller
Created November 1, 2014 02:20
Show Gist options
  • Select an option

  • Save xander-miller/8b9fb7047de361d2da7c to your computer and use it in GitHub Desktop.

Select an option

Save xander-miller/8b9fb7047de361d2da7c to your computer and use it in GitHub Desktop.
class Array
def new_any?(&block)
if block_given?
selected = self.select(&block)
else
selected = self
end
if selected.length == 0
false
else
true
end
end
end
## The hotshot version -- three lines!
## Walkthrough at https://www.bloc.io/resources/new-any-walkthrough
# class Array
# def new_any?(&block)
# selected = self.select(&block) if block_given?
# subarray = selected || self
# subarray.length > 0
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment