Created
December 3, 2010 15:03
-
-
Save jacegu/727068 to your computer and use it in GitHub Desktop.
More about open classes
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 String | |
def to_camel_case | |
return self if self == "" | |
words = self.split | |
words[1..words.size].each { |word| word.capitalize! } | |
words.join('') | |
end | |
def to_snake_case | |
self.downcase.gsub(/\s/, '_') | |
end | |
end | |
puts "run this method".to_camel_case | |
puts "run this method".to_snake_case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment