Skip to content

Instantly share code, notes, and snippets.

@tessafallon
Forked from ashleygwilliams/count_sentences.rb
Created November 15, 2013 13:58
Show Gist options
  • Save tessafallon/7484685 to your computer and use it in GitHub Desktop.
Save tessafallon/7484685 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