Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Question about #coerce

Reply
Thread Tools

Question about #coerce

 
 
Jim Cain
Guest
Posts: n/a
 
      07-09-2003
This is my understanding of the customary use of coerce: it is a request
to convert the receiver into the same type as the argument:

x.coerce(y)

is asking x to return a copy of itself that is the same class as y. I
understand that the return value is an array: [y1, x1].

What if x cannot be represented in the same class as y, but both could
be represented in a third class? Is it acceptable to return [y1, x1]
such that both objects have been rendered in a third class?

What if nothing can be done? Is it customary to raise an exception, or
return something like [y, nil]?

I'm working on implementing #coerce in my Oracle library, and I want to
make sure I do it the Ruby Way as much as possible.


 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      07-09-2003
Hi,

In message "Question about #coerce"
on 03/07/09, Jim Cain <(E-Mail Removed)> writes:

|What if x cannot be represented in the same class as y, but both could
|be represented in a third class? Is it acceptable to return [y1, x1]
|such that both objects have been rendered in a third class?

Acceptable. It's only reason to return converted y1 *and* x1 from
coerce, although no known class does that yet.

|What if nothing can be done? Is it customary to raise an exception, or
|return something like [y, nil]?

Raise TypeError exception.

matz.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments