It's a known issue. The bug was reported at #9005 and #9141.
Object#define_singelton_method in Ruby 2.1.0 defines private methods?
Question
object = Object.new
object.define_singleton_method(:foo) do
:bar
end
object.foo
fails with private method `foo' called for #<Object:0x00000001e89580> (NoMethodError)
. Ruby 2.0.0 does not behave like that. Is this a bug in 2.1.0 or intentional change?
La solution
Autres conseils
Since define_singleton_method
(and the other define_method
methods) now return a symbol of the method name, you can fix this by adding public
in front of any call to define_method
.
public define_method(:foo) { :bar }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow