Make private method public in Subclass in Ruby
Today I've Learned postclass Foo
private
def my_method
'it work !'
end
end
Foo.new.my_method
# => NoMethodError: private method `my_method' called for #<Foo:0x00000003ddb8e8>
Foo.send :public, :my_method
Foo.new.my_method
# => "it work !"
class Bar < Foo
public :my_method
end
Foo.new.my_method
# => NoMethodError: private method `my_method' called for #<Foo:0x00000003ddb8e8>
Bar.new.my_method
# => "it work !"
source
Entire blog website and all the articles can be forked from this Github Repo