Created
May 7, 2009 15:29
-
-
Save marano/108160 to your computer and use it in GitHub Desktop.
A core string extension that Ive used many times.
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
class String | |
def canonical | |
mb_chars.strip.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s | |
end | |
def trim | |
gsub(/ /,'') | |
end | |
def self.random(len = 10) | |
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a | |
newstring = "" | |
1.upto(len) { |i| newstring << chars[rand(chars.size-1)] } | |
return newstring | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment