In my specific case, I have a Time-derived class that I created through
the API, and I have a method that needs to adjust the underlying time by
a specific offset.
I’m trying to do the equivalent of self.+= (fixnum) but it doesn’t work.
Why wouldn’t I be able to call += or = for my derived-class ?
The class is very simple and adds an instance variable (with
getter/setter), and a method for ‘fixing up’ the time (for a specific
need). Unfortunately, I haven’t found a way for the ‘fix up’ method to
modify itself via the inherited Time methods.
It’s a pretty simple requirement, and it’s kind of frustrating to run
into this brick wall after having handled the rest of the API ‘fairly
well’. It seems odd that a derived-class of Time can’t even modify itself.
If I’m reading correctly though, are you saying that I’ll have to make
my method create a new time object, add to it (I’m assuming I >can< call
Time#+() ?) and return the the new instance ? (forcing the user to call
x = x.fixup)
Yukihiro Matsumoto wrote:
In message “Question about Ruby extension API” > on 02/08/27, “Bennett, Patrick” Patrick.Bennett@inin.com writes:
I’ve looked all over but can’t find the function call for doing a simple assignment (!)
It depends on what you want to assign to.
If it is a local variable, reconsider your design. You cannot modify
local variables from within a C function, since a C function is a
method, and a method cannot modify local variables of outer methods.
If it is an instance variable, use rb_ivar_set(). For a global
variable, rb_gvar_set() is available.