String#count_sentences returns the number of sentences in a complex string Failure/Error: expect(complex_string.count_sentences).to eq(4)
class String
def count_sentences
scan(/[.!?]+(?=\s|\z)/).size
end
end
str = "Learning Ruby is great!!!! The course cost $2.43... How much??!"
str.count_sentences
#=> 3