Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Doing a splat within a C extension

Reply
Thread Tools

Doing a splat within a C extension

 
 
Daniel Berger
Guest
Posts: n/a
 
      11-03-2005
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

 
Reply With Quote
 
 
 
 
ts
Guest
Posts: n/a
 
      11-03-2005
>>>>> "D" == Daniel Berger <(E-Mail Removed)> writes:

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






 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      11-03-2005

ts wrote:
> >>>>> "D" == Daniel Berger <(E-Mail Removed)> writes:

>
> 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

 
Reply With Quote
 
ts
Guest
Posts: n/a
 
      11-03-2005
>>>>> "D" == Daniel Berger <(E-Mail Removed)> writes:

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





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby 1.9 splat in return statement, bug or feature? Gary Wright Ruby 3 06-03-2009 06:30 AM
splat operator Question. Pedro Del Gallego Ruby 1 05-20-2007 11:29 AM
'**' as hash splat? Trans Ruby 12 10-26-2006 03:49 PM
redefining splat? Adam Shelly Ruby 10 10-03-2006 03:51 PM
Splat, #to_ary and #to_a Eero Saynatkari Ruby 18 09-20-2006 05:22 PM



Advertisments