Doing a splat within a C extension

D

Daniel Berger

Hi all,

Say I have an array VALUE. How would I splat that value within a C
extension?

/* test.c */
VALUE ary1 = rb_ary_new();
VALUE ary2 = rb_ary_new();

rb_ary_push(ary2, rb_str_new2("hello"));

rb_ary_push(ary1, ary2); /* Wrong - ary1 is now [["hello"]]
/* end test.c */

I know in this particular case I could use rb_ary_concat(), but I was
just wondering in general how you do this.

Thanks,

Dan
 
T

ts

D> I know in this particular case I could use rb_ary_concat(), but I was
D> just wondering in general how you do this.

I've not understood but look at splat_value() in eval.c


Guy Decoux
 
D

Daniel Berger

ts said:
D> I know in this particular case I could use rb_ary_concat(), but I was
D> just wondering in general how you do this.

I've not understood but look at splat_value() in eval.c


Guy Decoux

I saw that, but it didn't seem to be doing anything special. Also, I
can't use it if I want to, say, make a patch on array.c because it
doesn't see it yet.

I suppose I can just iterate of the array via RARRAY. I thought there
might be an easier way.

Regards,

Dan
 
T

ts

D> I saw that, but it didn't seem to be doing anything special.

it call rb_Array() with an exception for Qnil

rb_ary_concat(rb_Array()) do a splat


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top