From: James Harrison Date: 2010-07-14T01:14:04+09:00 Subject: Re: Ruby garabage collector On Jul 13, 2010, at 9:59 AM 7/13/10, Abder-Rahman Ali wrote: > Bruno Antunes wrote: >> On 13-07-2010 17:30, Abder-Rahman Ali wrote: >>> >>> Thanks. >> >> a = [1,2,3].find {|x| x > 3} >> >> puts a >> >> >> In this (maybe too simple) example, x is garbage-collected once flow >> leaves the block. > > Thanks Bruno. > > But, I'm always getting as output: > 1 > 2 > 3 > > Even if I type {|x| x < 3} > > Isn't your program trying to say find the values > 3 ? > > In other words, why don't I get some sort of error since I'm requesting > something not here? > 3 > > Thanks The point of the example is that x doesn't exist any more outside of the block. The array correctly returns the output "nil", as no values inside the array are greater than 3. I'm not sure what you're doing wrong: probably a typo somewhere. metatron:~ james$ irb >> a = [1,2,3].find {|x| x > 3} => nil >> puts a nil => nil >> puts x NameError: undefined local variable or method `x' for main:Object from (irb):3