Only detect encoding if the Ruby supports it

Fixed #88 introduced by #87.