From: Eric Christopherson Date: 2012-08-17T01:53:24+09:00 Subject: Re: Methods with same name and parameters in a single class. On Thu, Aug 16, 2012 at 11:06 AM, Rubyist Rohit wrote: > I saw a sample code of Ruby where in a class can have two methods with > the same name and same set of parameters: > > For example: > > class method_versions > def method > puts "first" > end > > def method > puts "second" > end > end > > On executing: method_versions.new.method > it returns: second > > Just in case I want to return the older version of the method, what > could be done? Any time a method is defined, it overrides any previous definition of a method by that name (regardless of the argument list of either definition). The only way to access the previous definition is to first save it in an alias: class Method_versions def method puts "first" end alias :old_method method def method puts "second" end end mv = Method_versions.new mv.old_method mv.method