Ruby/C newbie question

D

Dave Sims

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
 
T

Tilman Sauerbeck

Dave Sims said:
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
 
D

Dave Sims

That would be it. Thanks Tilman.

Tilman said:
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top