Created
November 1, 2014 02:20
-
-
Save xander-miller/8b9fb7047de361d2da7c to your computer and use it in GitHub Desktop.
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
| 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