Backport Pathname#sub

Definition is taken from Ruby 1.8.7.