use feature detection to decide which implementation to use

Decouple the code from the particular Ruby version.