共享作用域

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def define_methods
  shared = 0

  Kernel.send :define_method, :counter do
    p shared
  end

  Kernel.send :define_method, :inc do |x|
    shared += x
  end
end

define_methods

counter # => 0
inc(4) 
counter # => 4