use rb_ary_entry() and rb_ary_subseq() instead of RARRAY_PTR

* Based on a patch by Dirkjan Bussink
* See MRI Bug #8399: https://bugs.ruby-lang.org/issues/8399