From: Josh Cheek Date: 2012-08-19T15:16:50+09:00 Subject: Re: Methods with same name and parameters in a single class. --f46d044288608c090004c7985692 Content-Type: text/plain; charset=ISO-8859-1 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? > > -- > Posted via http://www.ruby-forum.com/. > > Subclass it, then override it. If you want to call the original, invoke `super` class C def m 'the original' end end class C2 < C def m "I override #{super}" end end C2.new.m # => "I override the original" --f46d044288608c090004c7985692 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Aug 16, 2012 at 11:06 AM, Rubyist Rohit <lists@ruby-forum.com> wrote:

Subclass it, then override it. If you = want to call the original, invoke `super`


class C
=A0 def m=A0=A0=A0 'the original'
=A0 end
end

class C2 < C=
=A0 def m
=A0=A0=A0 "I override #{super}"
=A0 end
end

C2.new.m= # =3D> "I override the original"

--f46d044288608c090004c7985692--