I think here you need to check what you're encoding?

If val is a MongoRegexp, then append 's' if `options & Regexp::MULTILINE`, and append 'm' if `options & Regexp::DOTALL`.

If val is a Regexp, append 's' if `options & Regexp::MULTILINE`, as you've done here.