>>>>> "M" == Martin J Laubach <mjl / emsi.priv.at> writes:

M>   I'd rather have a const attribute which makes the object immutable.

 Well an object can be immutable, but this is different for a variable 

moulon% cat b.rb
#!/usr/bin/ruby
a = [1, 2].freeze
begin
    a.push 3
rescue
    puts $!
end
a = 24
p a
moulon% 

moulon% b.rb
can't modify frozen array
24
moulon% 


M> 	foo = 42
M> 	bar.each { |foo| foo.doSomething(); }
M> 	...foo is no longer 42

M>   which would have been avoided by defining the second foo as block
M> local -- by the way, it is a formal parameter for the block, why
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 No, it's not a formal parameter for the block. It's best to see it as an
assignement to a variable.

 There are many discussions on ruby-talk about this subject, perhaps you
 can take a look at the archive

  http://www.ruby-talk.com/


M> does it even think about touching the foo from outside the block?
M> This looks so wrong to me.

 Probably because you see it in the wrong way :-)


Guy Decoux