Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
object = Object.new object.define_singleton_method(:foo) do :bar end object.foo
失败private method `foo' called for #<Object:0x00000001e89580> (NoMethodError)。Ruby 2.0.0 的行为并非如此。这是 2.1.0 中的错误还是有意更改?
private method `foo' called for #<Object:0x00000001e89580> (NoMethodError)
这是一个已知问题。该错误在#9005和#9141报告。
由于define_singleton_method(和其他define_method方法)现在返回方法名称的符号,您可以通过public在任何对define_method.
define_singleton_method
define_method
public
public define_method(:foo) { :bar }