Three Ways to Redefine a Private Method
Learn the different ways to redefine a private method and evaluate the impact of each approach.
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Learn the different ways to redefine a private method and evaluate the impact of each approach.
Comments
Why would I want to redefine a private method?
Brad is asking the important question, but it’s also worth pointing out that variable scoping in Ruby (public, protected, private) is merely a suggestion and not a hard barrier like it is in other languages. There’s also this way of calling a private method: obj.send(:oh_you_think_this_is_private?)
This was done in a real project I worked by a developer who redefined a private method in ActiveResource. I don’t recommend it. But you will encounter these kind of horrible code you need to deal with during upgrade. If you know how this works, you will be able to cleanup the code.
Post a comment