yield works, but no block given 
Author Message
 yield works, but no block given

On the subject of 'yield called out of block': the following code gives
that error and block_given? returns false, but at the same time yield
manages to use the block. Is yield psychic? I'm using
RUBY_VERSION==1.6.5.

  class A
    def each
      p block_given?
      yield 1; yield 2; yield 3
      [4,5,6].each
    end
  end

  class B
    def each
      A.new.each
    end
  end

  B.new.each { |x| p x }

==>
  false
  1
  2
  3
  LocalJumpError: yield called out of block

--
Joel VanderWerf                          California PATH, UC Berkeley

http://www.*-*-*.com/                       FAX (510) 231-9512



Thu, 22 Apr 2004 16:00:03 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. yield works, but no block given

2. block.call vs. yield

3. block , yield and proc?

4. "yield called out of block"

5. block/yield puzzle

6. Creating a method given a block

7. Creating a method given a block

8. Explicitly giving block/proc binding?

9. std blocks vs blocks+cache ( was: block behavior)

10. Works OK except when no path is given

11. Common statement does not work with gfortran, but g95 gives the correct answer

12. Block formatting script not working

 

 
Powered by phpBB® Forum Software