On Nov 12, 5:59=A0pm, Tarek Other <cashew... / yahoo.com> wrote:

>
> i.e.) I want to know if there is a way to call the block such that it
> knows or has access to all the local variables of the caller without
> having to pass those local variables in.

Hi Tarek,

Yes, this is the standard behavior of blocks.  Blocks are closures,
which means that they have access to the surrounding environment.

For example, this code works just fine, even though "y" is a local
variable used set outside the block and used inside the block:

=3D=3D=3D=3D

def method1(&block)
  0.upto(12) do |v|
    yield v
  end
end

def method2(y)
  method1 do |z|
    puts "#{y} * #{z} =3D #{y * z}"
  end
end

puts "Let's do the 3 times tables:"
method2(3)

=3D=3D=3D=3D

I hope that helps,

Eric

=3D=3D=3D=3D

Are you looking for on-site Ruby or Ruby on Rails training
that's been highly reviewed by former students?
http://LearnRuby.com