On 7/14/06, Robert Dober <robert.dober / gmail.com> wrote: > On 7/14/06, Sean O'Halpin <sean.ohalpin / gmail.com> wrote: > > > > On 7/14/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote: > > > On Fri, 14 Jul 2006 transfire / gmail.com wrote: > > > > > > > (class << File; self; end).instance_eval { > > > > define_method(:open,&open_m) > > > and the block? > > > > > > -a > > > -- > > > suffering increases your inner strength. also, the wishing for > > suffering > > > makes the suffering disappear. > > > - h.h. the 14th dali lama > > > > > I had to cheat ;) > > > > File::OPEN_M = open_m > > class File > > eval " > > def self.open(*args, &block) > > OPEN_M.call(*args, &block) > > end > > " > > end > > > > The problem is - as I'm sure you know - that define_method doesn't > > honour the block argument of the method reference. I'd be very > > interested to see if you can do it cleanly in ruby 1.8. > > > > Regards, > > Sean > > > > > Block behavior is preserved though when we store a reference to a method > e.g. > ----------------------- 8< ------------------------------ > class X > def x(*args,&block) > block.call(1764) if block > end > end > > OLD = X.instance_method :x > > class X > def x; "rubbish"; end > end > > class X > > define_method(:x, OLD ) > > end > > X.new.x{ |a| puts a } > ----------------------- >8 ---------------------------------- > > That should do the trick, no? > But I *cannot* make it work with IO :(, some internal magic, maybe? > > Cheers > Robert > > Excellent. Don't use the & to convert the Proc into a block - just use the method reference directly. Are you getting the "singleton method called for a different object (TypeError)" error? Thanks, Sean