From: "ara.t.howard" Date: 2007-10-15T01:42:57+09:00 Subject: Re: Parameter in a block is not local? On Oct 14, 2007, at 8:42 AM, SpringFlowers AutumnMoon wrote: > I thought a iterator with a block is like an nameless function call... > so if it is a function call, the parameter is local. > but for the following, the output is surprising: > > a = 1 > p a > > 1.upto(10) {|a| p a} > > p a one way to think about it (not entirely correct) is this - if the parameter exists *already* it is reused - if not a block local var is created this 1.upto(10){|a| p a} p a will throw an error - as you probably know. it's a fine line between having function call semantics and closure ones. we all want this to work message = 'hello world' 42.times{ p message } of course. so it's rather tricky. you can search the archives but i *think* the new rule is that introducing a var like so method{ |some_var| ... will introduce a block local var (as you are expecting above), while this method{ p some_var will not. i could be confused on this though, it really gets confusing to not violate POLS (referring to mine here) in all cases http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l7 http://www.davidflanagan.com/blog/2007_08.html#000137 and, of course, search the archives - matz has spelled out the changes several times. kind regards. a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama