[LRUG] Getting rid of 'proc'

Paul Battley pbattley at gmail.com
Tue Apr 17 02:35:38 PDT 2007


Following on from last night's discussion about the use of 'proc' in
Paolo's TabNav plugin, here's a brief demonstration of how to evaluate
the block in the right context without needing 'proc' at all:

---

#!/usr/bin/env ruby

class A
  def initialize
    @foo = 42
  end

  def define(&blk)
    @fn = blk
  end

  def evaluate
    instance_eval(&@fn)
  end
end

a = A.new
a.define do
  p @foo
end
a.evaluate # => 42

---

Paul.



More information about the Chat mailing list