From: Michael Neumann Date: 2001-02-11T20:17:51+09:00 Subject: [ruby-talk:10705] Re: Passing on a block to a called method On Sun, 11 Feb 2001, Michael Schuerig wrote: > Currently, when I want to pass on the block given to one method to > called method, I do it like this: > > openAsText(file) do |f| > f.each do |l| > ... > end > end > > def openAsText(file) > block = Proc.new > > filter = buildTextFilter(file) > > if filter.empty? > File.open(file) { |f| block.call(f) } > else > IO.popen("cat #{file} #{filter}") { |f| block.call(f) } > end > end Have you tried "yield" ? Substitute each "block.call(f)" through a "yield f", that should work. > > What I'm wondering about is whether this conversion to a Proc is really > necessary or if there's a more direct way to pass on the block. > > Michael > > -- > Michael Schuerig > mailto:schuerig@acm.org > http://www.schuerig.de/michael/ > -- Michael Neumann