RubyFlow The Ruby and Rails community linklog

Three Ways to Redefine a Private Method

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

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in