Sam Kong wrote:
> Can somebody help me understand what he meant?
> Closures in other languages are different from Ruby?
> And if possible, I want to see the *interesting code demos".

Here's an example that happens regularly in testing scenarios:

  def test_callback_gets_called
    cb_called = false
    widget = Widget.new
    widget.register_callback { cb_called = true }
    widget.do_something
    assert_true cb_called, "Expected the callback to be called"
  end

Without 'full' closures that can modify the bindings, one would have to 
turn cb_called into an object that could be modified, (e.g. an array):

  def test_callback_gets_called
    cb_called = [ false ]
    widget = Widget.new
    widget.register_callback { cb_called[0] = true }
    widget.do_something
    assert_true cb_called[0], "Expected the callback to be called"
  end

--
-- Jim Weirich

-- 
Posted via http://www.ruby-forum.com/.