From: Tim Hunter Date: 2003-03-16T23:58:11+09:00 Subject: Re: vcard 0.1 - how to do return values that can have 0, 1, or >1 cardinality In RMagick, the Image.read method reads an file that can contain 1 or more frames (an animated GIF, for instance). The method always returns an array of image objects. If no error occurs the array contains 1 or more elements. If you know you're going to be reading a file containing a single frame, you can code img = Magick::Image.read('mom.jpg').first This is inelegant but better, imho, than having 2 methods, one that returns a single image and one that returns an array of images. On Sun, 16 Mar 2003 07:21:26 +0900, Sam Roberts wrote: > 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