Ruby/C newbie question

Discussion in 'Ruby' started by Dave Sims, Jul 28, 2005.

  1. Dave Sims

    Dave Sims Guest

    I'm trying to set a char at a particular index in a Ruby String in C
    using the rb_funcall method, but since there is no text signature for
    this method call (that I know of), I'm having a hard time with it. Right
    now I'm messing with something like:

    rb_funcall(textString, rb_intern("[]="), 2, index);

    which throws an exception with the message: "`[]=': cannot convert false
    into String (TypeError)"

    Any ideas?

    I just need the C equivalent of "String"[n].

    thanks,
    Dave
     
    Dave Sims, Jul 28, 2005
    #1
    1. Advertisements

  2. Dave Sims <> [2005-07-29 05:02]:
    > I'm trying to set a char at a particular index in a Ruby String in C using the
    > rb_funcall method, but since there is no text signature for this method call
    > (that I know of), I'm having a hard time with it. Right now I'm messing with
    > something like:
    >
    > rb_funcall(textString, rb_intern("[]="), 2, index);


    rb_funcall (s, rb_intern ("[]="), 2, INT2FIX(0), rb_str_new2 ("A"));

    That would change the first character of the String s to "A".

    Regards,
    Tilman

    --
    learn to quote: http://www.netmeister.org/news/learn2quote.html
     
    Tilman Sauerbeck, Jul 28, 2005
    #2
    1. Advertisements

  3. Dave Sims

    Dave Sims Guest

    That would be it. Thanks Tilman.

    Tilman Sauerbeck wrote:

    >Dave Sims <> [2005-07-29 05:02]:
    >
    >
    >>I'm trying to set a char at a particular index in a Ruby String in C using the
    >>rb_funcall method, but since there is no text signature for this method call
    >>(that I know of), I'm having a hard time with it. Right now I'm messing with
    >>something like:
    >>
    >> rb_funcall(textString, rb_intern("[]="), 2, index);
    >>
    >>

    >
    >rb_funcall (s, rb_intern ("[]="), 2, INT2FIX(0), rb_str_new2 ("A"));
    >
    >That would change the first character of the String s to "A".
    >
    >Regards,
    >Tilman
    >
    >
    >
     
    Dave Sims, Jul 28, 2005
    #3
    1. Advertisements

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. DaZoner
    Replies:
    1
    Views:
    213
    Aleksei Guzev
    Oct 14, 2003
  2. Artco News
    Replies:
    0
    Views:
    152
    Artco News
    Oct 13, 2003
  3. Jacek Olszak
    Replies:
    2
    Views:
    222
    Jacek Olszak
    Nov 10, 2005
  4. arnuld fraser

    only 1 question about RUBY from newbie

    arnuld fraser, Jan 16, 2006, in forum: Ruby
    Replies:
    5
    Views:
    240
    arnuld fraser
    Jan 18, 2006
  5. anne001
    Replies:
    1
    Views:
    946
  6. Manish Kalra
    Replies:
    2
    Views:
    195
    _-_ Daniel _-_
    Dec 2, 2008
  7. Jerry C.
    Replies:
    8
    Views:
    566
    Uri Guttman
    Nov 23, 2003
  8. Dennis Lee Bieber

    Re: Newbie to python. Very newbie question

    Dennis Lee Bieber, Apr 7, 2013, in forum: Python
    Replies:
    1
    Views:
    154
    Miki Tebeka
    Apr 8, 2013
Loading...