On 7/14/06, Robert Dober <robert.dober / gmail.com> wrote: > [snip] > > > > > > > > > Excellent. Don't use the & to convert the Proc into a block - just use > > the method reference directly. > > > Too much honor, I seem to post too fast, furthermore the idea is ara's not > mine :) > > Are you getting the "singleton method called for a different object > > (TypeError)" error? > > > > Thanks, > > Sean > > > > > Exactly > and though my original code is not well documenting the behavior ara is > exploiting it really does seem to be a problem because of the "internal" > nature of IO. > Here is eventually the code mimicking the structure of the inherited class > method "open" and one can see that it works perfectly well: > > class X # role of IO > class << self > def x(*args,&block) # role of open > block.call(1764) if block > end > end > end > > OLD = X.method :x > > class Y < X # role of File > class << self > def x; "rubbish"; end > end > end > > class Y > class << self > define_method(:x, OLD ) > end > > end > > Y.x{ |a| puts a } > > Cheers > Robert > > Hmmm. I'm still getting "singleton method called for a different object (TypeError)" for this (ruby 1.8.4 (2005-12-24) [i386-mswin32]). Sean