Strip comments from a string

func strip_comment(s) {
    (s - %r'[#;].*').strip
}

[" apples, pears # and bananas",
 " apples, pears ; and bananas",
 " apples, pears "].each { |s|
    say strip_comment(s).dump;
}

Output:

"apples, pears"
"apples, pears"
"apples, pears"