Skip to content

Instantly share code, notes, and snippets.

@ashleygwilliams
Last active December 28, 2015 10:09
Show Gist options
  • Save ashleygwilliams/7484623 to your computer and use it in GitHub Desktop.
Save ashleygwilliams/7484623 to your computer and use it in GitHub Desktop.
# 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
class String
def count_sentences
split(/\.|\?|!/).length
end
end
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