这似乎不起作用:
class Test
private
define_method :private_method do
"uh!"
end
end
puts Test.new.private_method
最佳答案
Test.instance_eval { private :private_method }
或者,直接运行
private :private_method
来自 Test
类。
关于ruby - 如何将方法动态定义为私有(private)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3782026/