[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: not sure what is wrong. strange error

Gavin Kistner

9/15/2006 6:45:00 PM

From: Nathan Smith [mailto:nsmith5@umbc.edu]
> It's too bad Ruby does not allow overloaded methods. It makes
> more sense,
> IMHO, in this case to have two constructors, each of which perform two
> different 'functions', rather than having if/else/case
> statements inside
> the constructor with default arguments.

'Constructors' in ruby are just initializers that get run after the
internal 'new' allocates the object. The only thing special about
#initialize is that it happens to get called after you create a new
instance.

You can create as many different 'constructor' methods of the class as
you like. It's not parameter overloading, but (in my opinion) that's a
good thing.

class Circle
attr_accessor :radius

def initialize( radius )
@radius = radius
end

def self.withradius( r )
self.new( r )
end

def self.witharea( area )
self.new( Math.sqrt( area / Math::PI ) )
end

def self.withcircumference( circumference )
self.new( circumference / 2 / Math::PI )
end

def self.clone( circle )
self.new( circle.radius )
end

def area
Math::PI * @radius ** 2
end

def circumference
2 * Math::PI * @radius
end
end

p c1=Circle.new( 10 ),
c2=Circle.witharea( 100 ),
c3=Circle.withcircumference( 50 ),
c4=Circle.clone( c1 )

#=> #<Circle:0x2833504 @radius=10>
#=> #<Circle:0x2832e60 @radius=5.64189583547756>
#=> #<Circle:0x2832c94 @radius=7.95774715459477>
#=> #<Circle:0x2832c08 @radius=10>

2 Answers

*US*

9/1/2010 3:43:00 AM

0

"at least 15 countries provided warnings to the Bush administration - some of them
extremely specific about what, when, how"

http://www.oilempire.u...

There was absolutely no effort whatsoever to protect the victims.

In fact, Bush and Cheney did things to guarantee they'd be harmed.

BDK

9/1/2010 4:51:00 AM

0

In article <qrir76ti5qiq2gljtpp57u3op9l50cnstp@4ax.com>, * US * says...
> "at least 15 countries provided warnings to the Bush administration - some of them
> extremely specific about what, when, how"
>
> http://www.oilempire.u...
>
> There was absolutely no effort whatsoever to protect the victims.
>
> In fact, Bush and Cheney did things to guarantee they'd be harmed.
>

LOL, I love kooky pages like that. All that's missing is a truly
obnoxious color scheme.


--
BDK, non-jew leader of the non-existant paid jew shills!