From: Justin Johnson Date: 2002-07-24T21:07:48+09:00 Subject: Re: Eval question I see. Thanks. Is there anyway other way to create locals without explicitly setting them? -- Justin Johnson. "Tom Gilbert" wrote in message news:20020724113537.GR6415@offended.co.uk... > * Justin Johnson (justinj@mobiusent.com) wrote: > > I've got a question about 'eval'. In the following example (which doesn't > > work by the way) where does 'val' live? > > > > class MyClass > > def tryIt( str ) > > eval str > > p val > > end > > end > > > > a = MyClass.new > > a.tryIt( "val = 10" ) > > > > I was initially thinking that 'val' would be treated as a local to 'tryIt'. > > Maybe 'eval' works a little differently to how I thought it might? > > It's local to the scope of the string being eval'd. Try this: > > class MyClass > def tryIt( str ) > val = eval str > p val > end > end > > a = MyClass.new > a.tryIt( "val = 10" ) > > Tom. > -- > .^. .-------------------------------------------------------. > /V\ | Tom Gilbert, London, England | http://linuxbrit.co.uk | > /( )\ | Open Source/UNIX consultant | tom@linuxbrit.co.uk | > ^^-^^ `-------------------------------------------------------' >