Doing a splat within a C extension

Discussion in 'Ruby' started by Daniel Berger, Nov 3, 2005.

  1. 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
     
    Daniel Berger, Nov 3, 2005
    #1
    1. Advertising

  2. Daniel Berger

    ts Guest

    >>>>> "D" == Daniel Berger <> 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
     
    ts, Nov 3, 2005
    #2
    1. Advertising

  3. ts wrote:
    > >>>>> "D" == Daniel Berger <> 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
     
    Daniel Berger, Nov 3, 2005
    #3
  4. Daniel Berger

    ts Guest

    >>>>> "D" == Daniel Berger <> 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
     
    ts, Nov 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eero Saynatkari

    Splat, #to_ary and #to_a

    Eero Saynatkari, Sep 18, 2006, in forum: Ruby
    Replies:
    18
    Views:
    249
    Rick DeNatale
    Sep 20, 2006
  2. Adam Shelly

    redefining splat?

    Adam Shelly, Oct 2, 2006, in forum: Ruby
    Replies:
    10
    Views:
    373
    Martin Coxall
    Oct 3, 2006
  3. Trans

    '**' as hash splat?

    Trans, Oct 24, 2006, in forum: Ruby
    Replies:
    12
    Views:
    228
    Kalman Noel
    Oct 26, 2006
  4. Gary Wright
    Replies:
    3
    Views:
    122
    Macario Ortega
    Jun 3, 2009
  5. Pedro Del Gallego

    splat operator Question.

    Pedro Del Gallego, May 20, 2007, in forum: Ruby
    Replies:
    1
    Views:
    125
    Pedro Del Gallego
    May 20, 2007
Loading...

Share This Page