class String
  def strip_comment( markers = ['
    re = Regexp.union( markers ) 
    if index = (self =~ re)
      self[0, index].rstrip      
    else
      rstrip
    end
  end
end

p 'apples, pears 
str = 'apples, pears; and bananas'
p str.strip_comment
str = 'apples, pears and bananas '
p str.strip_comment
p str.strip_comment('and')
p .strip_comment
p .strip_comment