Trans
3/8/2007 11:07:00 PM
On Mar 8, 5:33 pm, "M. Ayhan" <mol...@yahoo.com> wrote:
> 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.