When I access an private variable, using @var inside a method, is there any way to capture that using a C extension? Or am I forced to use rb_iv_set/get to keep the ruby instance variable up to date? I would like for @var to call a C function; can this be done?
I've looked at CShadow, and it seems like it requires you to use self.var, which I've already figured out how to do.
Austin McDonald
Austin McDonald wrote:
When I access an private variable, using @var inside a method, is there any way to capture that using a C extension? Or am I forced to use rb_iv_set/get to keep the ruby instance variable up to date? I would like for @var to call a C function; can this be done?
AFAIK, there's no way to do this without hacking ruby.
I've looked at CShadow, and it seems like it requires you to use self.var, which I've already figured out how to do.
Yeah. If I knew a way to "hook" ivar access, CShadow would have used it. But ruby probably is more efficient without the hooks since it would always have to check for them, and allocate space for them.
One alternative is to declare the accessors protected.
I can see how it would be more efficient this way. Good work on CShadow, btw. Thanks!
Austin
Joel VanderWerf wrote:
ยทยทยท
Austin McDonald wrote:
When I access an private variable, using @var inside a method, is there any way to capture that using a C extension? Or am I forced to use rb_iv_set/get to keep the ruby instance variable up to date? I would like for @var to call a C function; can this be done?
AFAIK, there's no way to do this without hacking ruby.
I've looked at CShadow, and it seems like it requires you to use self.var, which I've already figured out how to do.
Yeah. If I knew a way to "hook" ivar access, CShadow would have used it. But ruby probably is more efficient without the hooks since it would always have to check for them, and allocate space for them.
One alternative is to declare the accessors protected.