From: Christoph Rippel Date: 2000-11-22T22:45:21+09:00 Subject: [ruby-talk:6517] Re: Question about the behavior of write attributes in blocks Thank you very much for your insightful (and speedy) response. Is it at all possible to write an iterator, which allows assignments inside a block? I have a vague understanding that the main obstacle is the fact that ``x=y'' does not involve a method invocation. I played around with the build in iterator for the Array class and came up with a ``program-let'' ************************************** def surprise(y) sep="---" j="A" for i in y do print i+sep i << j # this is a destructive method - similar to replace print i+sep i += j print i+sep i.replace "f" print i j.succ! puts end end dyn = Array.new(3,"x") sta = ["x","x","x"] surprise dyn puts surprise sta ************************************** with a rather surprising output ... >>x---xA---xAA---f >>xA---xAB---xABB---f >>xAB---xABC---xABCC---f >> >>x---xA---xAA---f >>x---xB---xBB---f >>x---xC---xCC---f I am not sure if this is a bug but it certainly violates the ruby principle of ``least surprise''. Any thoughts? Thanks, Christoph