How do I dynamically define a method as private?

后端 未结 3 854
刺人心
刺人心 2021-01-04 08:52

This does not seem to work:

class Test
  private

  define_method :private_method do 
    \"uh!\"
  end
end

puts Test.new.private_method
3条回答
  •  执念已碎
    2021-01-04 09:34

    Test.instance_eval { private :private_method }
    

    Or, just run

    private :private_method
    

    from within the Test class.

提交回复
热议问题