------art_21306_22862896.1152874552788
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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  pen_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  .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

------art_21306_22862896.1152874552788--