Forum: Ruby Hijack, or alias a method with a proc?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ffee7b5e77e3af62e73c26c7d7d8eafc?d=identicon&s=25 Jim (Guest)
on 2007-05-18 19:56
(Received via mailing list)

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

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

47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2007-05-18 20:16
(Received via mailing list)
Jim wrote:
> 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)
Ffee7b5e77e3af62e73c26c7d7d8eafc?d=identicon&s=25 Jim (Guest)
on 2007-05-20 06:40
(Received via mailing list)
Thanks Joel, I was certain it could be done. I appreciate your time
and knowledge.
On May 18, 2:14 pm, Joel VanderWerf <> wrote:
This topic is locked and can not be replied to.