methods that affect subsequently defined methods

Discussion in 'Ruby' started by M. Ayhan, Mar 8, 2007.

  1. M. Ayhan

    M. Ayhan Guest

    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

    --
    Posted via http://www.ruby-forum.com/.
     
    M. Ayhan, Mar 8, 2007
    #1
    1. Advertising

  2. M. Ayhan

    Trans Guest

    On Mar 8, 5:33 pm, "M. Ayhan" <> 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.
     
    Trans, Mar 8, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oodini
    Replies:
    1
    Views:
    1,846
    Keith Thompson
    Sep 27, 2005
  2. Jordan S.
    Replies:
    1
    Views:
    420
    Jordan S.
    May 23, 2008
  3. Peter Otten
    Replies:
    0
    Views:
    438
    Peter Otten
    Nov 30, 2010
  4. Peter Otten
    Replies:
    10
    Views:
    901
    Nobody
    Dec 2, 2010
  5. Dan Stromberg
    Replies:
    0
    Views:
    971
    Dan Stromberg
    Dec 6, 2010
Loading...

Share This Page