From: Sam Roberts Date: 2004-03-23T23:38:59+09:00 Subject: Re: How to pass a given block to a subroutine Is this what you want? /tmp % ruby -w y.rb hello world /tmp % cat y.rb def foo (*args, &ablock) subroutine(*args, &ablock) end def subroutine *args yield(*args) end foo("hello", "world") { |a,b| puts a; puts b; } Cheers, Sam Wrote Lothar Scholz , on Tue, Mar 23, 2004 at 11:32:04PM +0900: > Hello , > > I have a method 'foo' that takes a block, but the yield should > be done in a subroutine. > > ====================================================== > class Example > > def foo (*args) > subroutine *args > end > > def subroutine *arg > yield *arg # want to call the block given to foo > end > > end > > a = Example.new > a.foo(10,20) { |a,b| print "#{a + b}\n" } > ======================================================= > > If you ask why i want to do this: > i have to replace an existing subroutine with my own version, that > does something before yield is called. So i renamed the method > and must now find a way to call it from my version. > > > -- > Best regards, > Lothar mailto:mailinglists@scriptolutions.com > > -- Sam Roberts