Hijack, or alias a method with a proc?

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 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)

Thanks Joel, I was certain it could be done. I appreciate your time
and knowledge.
On May 18, 2:14 pm, Joel VanderWerf [email protected] wrote:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs