我正在编写一个方法来定义类中的实例方法; 与attr_accessor类似的东西:
class Foo
custom_method(:foo)
end
Run Code Online (Sandbox Code Playgroud)
我已经通过将custom_method函数添加到Module模块,并使用define_method定义方法来实现,这可以正常工作.但我无法弄清楚如何从课程中考虑可见性属性.例如,在以下类中
class Foo
custom_method(:foo)
private
custom_method(:bar)
end
Run Code Online (Sandbox Code Playgroud)
第一个生成的方法(foo)必须是公共的,第二个(bar)必须是私有的.我怎么做?或者,如何找到调用custom_method的上下文:private,public或protected?
谢谢!
ruby ×1