methods that affect subsequently defined methods

M

M. Ayhan

Hi,

I want to implement methods like Ruby's protected that will effect some
aspect of the subsequently defined methods. For example, I want write
sth like follows:

class Test
authorize_for :ROLE1, :ROLE2
def method1
...
end

def method2
...
end

authorize_for :ROLE3
def method3
...
end
end


In the def. on authorize_for method, I can use a global var to hold the
parameters passed and then use then in method_added callback.
However, once the class definition end, I no longer need those global
variables
and I couldn't find a way to mark them for gc (set to nil).

I need a way to be informed about the end of the class definition. I
considered set_trace_func but because there is no way to chain or
restore trace funcs after set, so that is not really an option.

I also checked for class_added callback, but according to the Ruby list,
it's been refused because of lack of concrete usage.

Is there any other way to accomplish this?

M. Ayhan
 
T

Trans

Hi,

I want to implement methods like Ruby's protected that will effect some
aspect of the subsequently defined methods. For example, I want write
sth like follows:

class Test
authorize_for :ROLE1, :ROLE2
def method1
...
end

def method2
...
end

authorize_for :ROLE3
def method3
...
end
end

In the def. on authorize_for method, I can use a global var to hold the
parameters passed and then use then in method_added callback.
However, once the class definition end, I no longer need those global
variables
and I couldn't find a way to mark them for gc (set to nil).

I need a way to be informed about the end of the class definition. I
considered set_trace_func but because there is no way to chain or
restore trace funcs after set, so that is not really an option.

I also checked for class_added callback, but according to the Ruby list,
it's been refused because of lack of concrete usage.

Is there any other way to accomplish this?

You might try facets annotations library.

T.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top