Created
January 14, 2011 23:15
-
-
Save wbailey/780475 to your computer and use it in GitHub Desktop.
Using a mixin to extend the object and use it's eigenclass
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
module MyString | |
def consonants | |
self.gsub /[aeiuo0-9]/i, '' | |
end | |
def vowels | |
self.gsub /[^aieou]/i, '' | |
end | |
def capitols | |
self.gsub /[^A-Z]/, '' | |
end | |
def lowercase | |
self.gsub /[^a-z]/, '' | |
end | |
def numbers | |
self.gsub /[^0-9]/, '' | |
end | |
end | |
puts str = "f2fp2LOCBVXBn2ifcgpy".extend(MyString) | |
%w{consonants vowels capitols lowercase numbers}.each {|m| puts "#{m}: #{str.send m}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment