From: John W Higgins Date: 2013-04-30T04:26:12+09:00 Subject: Re: How does Module#include differ from #prepend? --089e0163450a65c01004db84db1a Content-Type: text/plain; charset=ISO-8859-1 That darn google again - first hit ruby include vs ruby prepend John On Mon, Apr 29, 2013 at 12:21 PM, Love U Ruby wrote: > class Foo > def do_stuff > puts "doing stuff" > end > end > > module Wrapper > def do_stuff > puts "before stuff" > super > puts "after stuff" > end > end > > class Foo > prepend Wrapper > end > > Foo.new.do_stuff > p Foo.ancestors > > output: > ======= > before stuff > doing stuff > after stuff > [Wrapper, Foo, Object, Kernel, BasicObject] > #---------------------------- > > class Foo > def do_stuff > puts "doing stuff" > end > end > > module Wrapper > def do_stuff > puts "before stuff" > super > puts "after stuff" > end > end > > class Foo > include Wrapper > end > > Foo.new.do_stuff > p Foo.ancestors > > output: > ======= > before stuff > doing stuff > after stuff > [Wrapper, Foo, Object, Kernel, BasicObject] > > I didn't get the technical difference between these two. Any one please > help me. > > -- > Posted via http://www.ruby-forum.com/. > > --089e0163450a65c01004db84db1a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
That darn google again - first hit

ruby includ= e vs ruby prepend

John

On Mon, Apr 29, 2013 at 12:21 PM, Love U Ru= by <lists@ruby-forum.com> wrote:
class Foo
=A0 def do_stuff
=A0 =A0 puts "doing stuff"
=A0 end
end

module Wrapper
=A0 def do_stuff
=A0 =A0 puts "before stuff"
=A0 =A0 super
=A0 =A0 puts "after stuff"
=A0 end
end

class Foo
=A0 prepend Wrapper
end

Foo.new.do_stuff
p Foo.ancestors

output:
=3D=3D=3D=3D=3D=3D=3D
before stuff
doing stuff
after stuff
[Wrapper, Foo, Object, Kernel, BasicObject]
#----------------------------

class Foo
=A0 def do_stuff
=A0 =A0 puts "doing stuff"
=A0 end
end

module Wrapper
=A0 def do_stuff
=A0 =A0 puts "before stuff"
=A0 =A0 super
=A0 =A0 puts "after stuff"
=A0 end
end

class Foo
=A0 include Wrapper
end

Foo.new.do_stuff
p Foo.ancestors

output:
=3D=3D=3D=3D=3D=3D=3D
before stuff
doing stuff
after stuff
[Wrapper, Foo, Object, Kernel, BasicObject]

I didn't get the technical difference between these two. Any one please=
help me.

--
Posted via http://= www.ruby-forum.com/.


--089e0163450a65c01004db84db1a--