Last active
December 28, 2015 10:09
-
-
Save ashleygwilliams/7484623 to your computer and use it in GitHub Desktop.
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
# Write a method on String called `count_sentences` that returns the number of | |
# sentences in the string it is called on | |
class String | |
def count_sentences | |
# code goes here | |
end | |
end |
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 count_sentences | |
split(/\.|\?|!/).length | |
end | |
end |
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
require './count_sentences' | |
describe String, "#count_sentences" do | |
it "should return the number of sentences in a string" do | |
"one. two. three?".count_sentences.should eq(3) | |
end | |
it "should return zero if there are no sentences in a string" do | |
"".count_sentences.should eq(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment