# Methods that affect subsequently defined methods

**URL:** <https://www.ruby-forum.com/t/methods-that-affect-subsequently-defined-methods/88214>\
**Category:** Ruby\
**Created:** [March 8, 2007, 11:33pm UTC](https://www.ruby-forum.com/t/methods-that-affect-subsequently-defined-methods/88214 "2007-03-08T23:33:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSAyhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@MSAyhan](https://www.ruby-forum.com/u/MSAyhan)\
**Post date:** [March 8, 2007, 11:33pm UTC](https://www.ruby-forum.com/t/methods-that-affect-subsequently-defined-methods/88214/1 "2007-03-08T23:33:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MSAyhan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@MSAyhan](https://www.ruby-forum.com/u/MSAyhan)\
**Post date:** [March 9, 2007, 12:07am UTC](https://www.ruby-forum.com/t/methods-that-affect-subsequently-defined-methods/88214/2 "2007-03-09T00:07:30Z")

</div>

On Mar 8, 5:33 pm, “M. Ayhan” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> end
> 
> ```
> 
> 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.
