How to return more than one result from a method?

T

Tim Hunter

I'm trying to code a method that has two result values. The values are
very different objects: an Image (a large and complicated object) and a
plain ol' Ruby Float. I'm not sure what the best way to handle this is. I
could return them an Array with 2 elements, but that feels too
lightweight. I could return a Hash with 2 members. I could define a new
class with two attributes, but that feels too heavyweight. I even thought
of having the method yield to a block, passing the two results as
arguments to the block, but that just seems bizarre.

So I'm soliciting advice. How has this been solved before?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top