Created
May 13, 2010 02:12
-
-
Save viniciusteles/399401 to your computer and use it in GitHub Desktop.
This file contains 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
# Returns a copy of self with all +true+ elements removed. | |
# [ "a", true, "b", true, "c", true].compact_true #=> [ "a", "b", "c" ] | |
# | |
def compact_true | |
remove_elements(TrueClass) | |
end | |
# Returns a copy of self with all +false+ elements removed. | |
# [ "a", false, "b", false, "c", false].compact_true #=> ["a","b","c" ] | |
# | |
def compact_false | |
remove_elements(FalseClass) | |
end | |
private | |
def remove_elements(boolean_class) | |
self.clone.delete_if { |element| element.is_a?(boolean_class) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment