Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How call Ruby's internal C methods in Ruby?

Tags:

c

ruby

I'm trying to create a hash from an array and the documentation for http://ruby-doc.org/ruby-1.9/classes/Array.src/M000744.html shows an internal ruby method called ary_make_hash. The source uses this to diff arrays. The relevant line in the source is: ary_make_hash(to_ary(ary2), 0);

Is there a way to access the ary_make_hash function and other internal Ruby functions from inside Ruby? I ask since I'm trying to convert a huge array to a hash and I'd love to use the built in C methods since they're so much faster. (FYI I can see the speed difference by subtracting two arrays, which internally invokes the converter method). Thanks for any thoughts.

Robert

like image 675
rhh Avatar asked Aug 17 '26 02:08

rhh


1 Answers

in general if it's not in ruby.h, then it's not a "public" api looking for a method called rb_xxx might also help. GL.

like image 150
rogerdpack Avatar answered Aug 18 '26 16:08

rogerdpack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!