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