Last active
December 13, 2015 21:38
-
-
Save maxjacobson/4978111 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
class String | |
def word_count | |
self.split(" ").length | |
end | |
def char_count | |
self.chars.to_a.length | |
end | |
def contains(word) | |
self.gsub(/[^\w]/, " ").split(" ").count(word) | |
end | |
end | |
sentence = "I really, really, really love it when my dog licks my cat." | |
puts sentence.word_count | |
puts sentence.char_count | |
puts sentence.contains("really") | |
puts sentence.contains("dog") | |
puts sentence.contains("codecrew") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://blog.codecrewny.org/post/43399030283/code-crew-code-challenge-2