>>>>> "W" == Wai-Sun Chia <waisun.chia / compaq.com> writes:

W> rb_define_attr() just defines the accessor methods only, right?

 yes,

W> What about the actual variables @foo or @bar?

 rb_ivar_set()

W> I'd also appreciate any sample code.

pigeon% cat tt.c
#include <ruby.h>

static VALUE
tt_init(obj)
    VALUE obj;
{
    rb_ivar_set(obj, rb_intern("@foo"), rb_str_new2("foo"));
    rb_ivar_set(obj, rb_intern("@bar"), rb_str_new2("bar"));
    return obj;
}

void Init_tt()
{
    VALUE tt_cTt = rb_define_class("Tt", rb_cObject);
    rb_define_method(tt_cTt, "initialize", tt_init, 0);
    rb_define_attr(tt_cTt, "foo", 1, 0);
    rb_define_attr(tt_cTt, "bar", 1, 1);
}
pigeon% 

pigeon% ruby -rtt -e 'p Tt.new'
#<Tt:0x401a6a18  @bar="bar", @foo="foo">
pigeon% 



Guy Decoux