How to dynamically define a class method which will refer to a local variable outside?

前端 未结 3 1197
有刺的猬
有刺的猬 2021-02-02 09:27
class C
end

var = \"I am a local var outside\"

C.class_eval do
   def self.a_class_method
     puts var 
   end
end

I know, this is not correct, beca

3条回答
提交回复
热议问题