I’m a newcommer to Ruby and I haven’t read completely the book yet, so
excuse me for a very basic question.
What’s the way to signal to a NEW()'s caller that an object can’t be
created? To return NIL? To throw an exception?
Roman
I’m a newcommer to Ruby and I haven’t read completely the book yet, so
excuse me for a very basic question.
What’s the way to signal to a NEW()'s caller that an object can’t be
created? To return NIL? To throw an exception?
Roman
Throw the appropriate exception. I don’t think new can return anything
except the new object.
On Mon, 02 Dec 2002 06:33:11 +0900, Roman Rytov wrote:
I’m a newcommer to Ruby and I haven’t read completely the book yet, so
excuse me for a very basic question.What’s the way to signal to a NEW()'s caller that an object can’t be
created? To return NIL? To throw an exception?Roman
Hi,
In message “Validation during object creation” on 02/12/02, “Roman Rytov” rrytov@entopia.com writes:
What’s the way to signal to a NEW()'s caller that an object can’t be
created? To return NIL? To throw an exception?
Raise exceptions from “initialize” method.
matz.
If I understand correctly what you need, you may want to place
private_class_method :new
somewhere in your class definition.
Gennady.
On Sunday, Dec 1, 2002, at 13:33 US/Pacific, Roman Rytov wrote:
I’m a newcommer to Ruby and I haven’t read completely the book yet, so
excuse me for a very basic question.What’s the way to signal to a NEW()'s caller that an object can’t be
created? To return NIL? To throw an exception?Roman
“Tim Hunter” cyclists@nc.rr.com wrote in message
news:pan.2002.12.01.23.45.24.468256@nc.rr.com…
Throw the appropriate exception. I don’t think new can return anything
except the new object.
class X
def X.new
“Soon it will be Xmas”
end
end
X.new # ==> “Soon it will be Xmas”
Mikkel