I found another solution suggested by @leafac:
https://github.com/leafac/rbenv/commit/0ce9691578b7fbb4174ce0ae31e6d89c1678c09b#diff-f35b3df388b0c01ad40bb85555fc900cR11

What do you think about it?