>>>>> "C" == Chris Uzdavinis <chris / atdesk.com> writes:

C> def example
C>   a = X.new
C>   a.x = 111
C>   a.y = 222
C>   a.z = 333
C>   return a
C> end

 This is very quickly written

pigeon% cat tt.c
#include <ruby.h>
 
static VALUE tt_cX;
 
static VALUE
tt_example(self)
    VALUE self;
{
    VALUE res = rb_funcall(tt_cX, rb_intern("new"), 0, 0);
    rb_ivar_set(res, rb_intern("@x"), INT2NUM(111));
    rb_ivar_set(res, rb_intern("@y"), INT2NUM(222));
    rb_ivar_set(res, rb_intern("@z"), INT2NUM(333));
    return res;
}
 
void Init_tt()
{
    rb_require("x");
    tt_cX = rb_const_get(rb_cObject, rb_intern("X"));
    rb_define_singleton_method(tt_cX, "example", tt_example, 0);
}
 
pigeon% 

pigeon% cat x.rb
class X
  attr_reader :x, :y, :z
  attr_writer :x, :y, :z  
end
pigeon% 

pigeon% ruby -rtt -e 'p X.example'
#<X:0x4019f70c  @z=333, @y=222, @x=111>
pigeon% 


Guy Decoux