./ruby/test/closures2.rb

download original
class C

  def initialize
    @x=42
  end

  def cl
    proc {
      print "#{@x}\n"
    }
  end

end




c=C.new
cl=c.cl


cl.call

@x = 23

cl.call


# prints 42\n42\n

  
back to test

(C) 1998-2017 Olaf Klischat <olaf.klischat@gmail.com>