Hijack, or alias a method with a proc?

Discussion in 'Ruby' started by Jim, May 18, 2007.

  1. Jim

    Jim Guest

    Hello,

    I have a Menu class with a add_item method, which takes a name
    followed by a proc:

    Menu("TopLevelMenuName").add_item("NewMenuItemName") { puts "Hello" }

    I want to hijack this method so I can customize the menu in which the
    proc is associated.

    Class Menu
    alias :_add_item :add_item
    def add_item( *args )
    p args
    end
    end

    This captures the menuname string, but how do I get at the associated
    proc?

    Thanks.
     
    Jim, May 18, 2007
    #1
    1. Advertising

  2. Jim wrote:
    > Hello,
    >
    > I have a Menu class with a add_item method, which takes a name
    > followed by a proc:
    >
    > Menu("TopLevelMenuName").add_item("NewMenuItemName") { puts "Hello" }
    >
    > I want to hijack this method so I can customize the menu in which the
    > proc is associated.
    >
    > Class Menu
    > alias :_add_item :add_item
    > def add_item( *args )


    def add_item( *args , &block )

    > p args

    p args, block
    _add_item(*args, &block)

    > end
    > end
    >
    > This captures the menuname string, but how do I get at the associated
    > proc?
    >
    > Thanks.
    >



    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, May 18, 2007
    #2
    1. Advertising

  3. Jim

    Jim Guest

    Thanks Joel, I was certain it could be done. I appreciate your time
    and knowledge.
    On May 18, 2:14 pm, Joel VanderWerf <> wrote:
     
    Jim, May 20, 2007
    #3
    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. David Lozzi
    Replies:
    3
    Views:
    1,952
    David Lozzi
    Jun 1, 2005
  2. Replies:
    1
    Views:
    2,308
    nautonnier
    Jul 11, 2006
  3. grocery_stocker
    Replies:
    9
    Views:
    788
    grocery_stocker
    May 24, 2008
  4. richard
    Replies:
    8
    Views:
    451
    Adrienne Boswell
    Nov 21, 2008
  5. Dave

    Hijack Session

    Dave, Jan 8, 2004, in forum: ASP .Net Security
    Replies:
    2
    Views:
    131
    Keith
    Feb 1, 2004
Loading...

Share This Page