From: pongba Date: 2007-09-03T14:45:05+09:00 Subject: Re: How does ruby handle overloading? On Sep 3, 10:23 am, dbl...@wobblini.net wrote: > Hi -- > > > > On Mon, 3 Sep 2007, pongba wrote: > > On Sep 2, 9:25 pm, Sebastian Hungerecker > > wrote: > >> pongba wrote: > >>> what concerns me is that if, for > >>> instance, we have Matrix and Graph, and we'd like to be able to draw > >>> both of them (the two 'draw's would have the same semantic but > >>> different implementation logic), how 're we going to be able to > >>> overload draw on Matrix and Graph like what we do in C++ or Java: > > >>> void draw(Matrix); > >>> void draw(Graph); > > >> def draw(arg) > >> if arg.is_a? Matrix > >> do_stuff > >> elsif arg.is_a? Graph > >> do_other_stuff > >> end > >> end > > >> HTH, > >> Sebastian > >> -- > >> NP: Dream Theater - Honor Thy Father > >> Jabber: sep...@jabber.org > >> ICQ: 205544826 > > > But isn't type-switch generally believed to be a bad thing? > > It's actually class-switch (type and class aren't the same in Ruby), > and it's an expedient that can be useful in some situations but tends > to interfere with "thinking in Ruby", so to speak. Ruby generally is > more about objects and their capabilities, and less about which > classes happened to spawn them. > > David > > -- > * Books: > RAILS ROUTING (new!http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) Thanks, David. That helps :-)