Virtual instance-variable accessors

A

Austin McDonald

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
 
J

Joel VanderWerf

Austin said:
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.
 
A

Austin McDonald

I can see how it would be more efficient this way. Good work on
CShadow, btw. Thanks!

Austin
 

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,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top