Skip to content

Instantly share code, notes, and snippets.

@wbailey
Created January 14, 2011 23:15
Show Gist options
  • Save wbailey/780475 to your computer and use it in GitHub Desktop.
Save wbailey/780475 to your computer and use it in GitHub Desktop.
Using a mixin to extend the object and use it's eigenclass
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