>>>>> "f" == foo  <matju / cam.org> writes:

f> why not this?

 There is a small difference :

pigeon% cat b.rb
#!/usr/bin/ruby
class Class
   def method_missing(meth, *params)
      p "before method_missing"
      if iterator?
         self.new(*params).send(meth) { |p| yield p }
      else
         self.new(*params).send(meth) 
      end
      p "after method_missing"
   end
end

def a
   p "enter"
   File.each('b.rb') { |i| return }
   p "leave"
end

a
p "END"
pigeon%

pigeon% b.rb
"enter"
"before method_missing"
"END"
pigeon%

pigeon% cat b.rb
#!/usr/bin/ruby
class Class
   def method_missing(meth, *params, &block)
      p "before method_missing"
      self.new(*params).send(meth, &block)
      p "after method_missing"
   end
end

def a
   p "enter"
   File.each('b.rb') { |i| return }
   p "leave"
end

a
p "END"
pigeon%

pigeon% b.rb
"enter"
"before method_missing"
./b.rb:12:in `method_missing': return from proc-closure (LocalJumpError)
        from ./b.rb:12:in `a'
        from ./b.rb:16
pigeon% 


Guy Decoux