From: Ned Konz Date: 2002-07-25T14:15:13+09:00 Subject: Re: A Code Challenge On Wednesday 24 July 2002 08:56 pm, Tom Sawyer wrote: > Problem: > > given a proc p and an object o with method x, such that the arity > of x and p are the same, dynamically append p into x. > > statically you have this: > > class O > def x(a) > puts "do something with #{a}" > end > end > o = O.new > > then given: > > p = Proc.new { |a| puts "do something else with #{a}" } > > the goal is to dynamically modify instance o such that it were AS > IF it were an instantiation of: > > class O > def x(a) > puts "do something with #{a}" > puts "do something else with #{a}" > end > end > > ~transami You mean like this? class O def x(a) puts "do something with #{a}" end end o = O.new $p = Proc.new { |a| puts "do something else with #{a}" } def o.x(a) super $p.call(a) end o.x('abc') -- Ned Konz http://bike-nomad.com GPG key ID: BEEA7EFE