阅读背景:

为什么我在使用to_proc而不是使用Proc.new时调用instance_eval时出错?

来源:互联网 

I'm doing this and it works:

我这样做是有效的:

class B
  def value
    "X"
  end
end

class A
  def initialize(context)
    @context = context
  end

  def m
    Proc.new do
      value
    end
  end

  def execute
    @context.instance_eval(&m)
  end
end

A.new(B.new).execute #=> "X"
clas



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: