From: Sam Roberts Date: 2003-03-16T07:21:26+09:00 Subject: Re: vcard 0.1 - how to do return values that can have 0, 1, or >1 cardinality I used to have APIs that returned an array, a string, or nil (if there were multiple, 1, or no values). I thought it was cool. But... it turns out every time you call something you basically need a switch to figure out what to do with it! I also noticed that Enumrable.find_all() always returns an array, its just sometimes it has a size of zero. So, I've been drifting towards that. Currently, the _all() APIs return an array, or nil, so if the return value is true, then there is guaranteed to be at least one member, but I'm starting to feel there's a mismatch between this way, and the Ruby Way, so I might just always return an array for the _all() functions. I'm still thinking about it. What to other people do? I don't have experience with enough APIs to know. Cheers, Sam Quoteing rich@infoether.com, on Sun, Mar 16, 2003 at 05:34:48AM +0900: > I think the index method [] returning the preferred field (if pref is > specified) or the first (of many) is acceptable. I would not use the > index method if I wanted a full enumeration (and you provide methods > for that) but for quick access. If you had two work email addresses > (and none were preferred) I think as long as I get one, I would be > happy. > > if vcard[:email] > ...send email > end > > I would not want to have to always check for an Array vs. a String > thought...that would make code kind of messy. > > -rich > > On Saturday, March 15, 2003, at 03:18 PM, Alan Chen wrote: > >Well, you could always return an array. > > puts card[:email] #=> [ rich@infoether.com ]