Hi, Suppose I have written the below code: class Foo def show p "Good" end end Now is it possible in future to re-open the "show" method again to add some new logic,once the `class Foo` has been defined ?
on 2013-02-27 23:05
on 2013-02-27 23:13
look for alias and alias_method
on 2013-02-27 23:45
Hello Xavier, yes, it is possible. There are three options you have, depending on what you want: - Inheritance: Overwrite the method show in a subclass and then call super (if you need the new behavior independently of the old behavior) - Alias the old method show to something like "old_show" and then redefine show (if you want to call the old method); alias_method and alias are the tools for that - Just redefine the method (if you don't need the old method) Kind regards, Calvin