Can initialize b overloaded

class Point

attr:x_pos,true
attr:y_pos,true

def initialize(x_pos,y_pos)

end

#can initialize b overloaded!

def initialize(some_instance_of_point)

@x_pos=some_instance_of_point.x_pos

end

end

  1. Is the above snippet of code valid one in Ruby
    If not why?

  2. How to comment multilines?

Thanx in advance
Lokesh

···

Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Hello Sambasivan,

Friday, December 20, 2002, 10:13:01 AM, you wrote:

def initialize(x_pos,y_pos)
def initialize(some_instance_of_point)
#can initialize b overloaded!

no. use

def initialize(*args)
case args.size
when 1 …
when 2 …

  1. How to comment multilines?

=begin

=end

···


Best regards,
Bulat mailto:bulatz@integ.ru

Hi –

class Point

attr:x_pos,true
attr:y_pos,true

def initialize(x_pos,y_pos)

end

#can initialize b overloaded!

def initialize(some_instance_of_point)

@x_pos=some_instance_of_point.x_pos

end

end

  1. Is the above snippet of code valid one in Ruby
    If not why?

It’s valid, but it’s not overloading: it’s overriding. The most
recently defined method of a given name will be called, so your first
definition of #initialize will be discarded.

There’s a lot of discussion of method overloading, multiple dispatch,
etc. in the ruby-talk archive (http://www.ruby-talk.org). (Mainly
discussion of why Ruby doesn’t have them :slight_smile:

  1. How to comment multilines?

=begin

=end

or multiple #'s.

David

···

On Fri, 20 Dec 2002, Sambasivan LokeshKumar wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav