module / class best practices

J

Joe Van Dyk

I'm writing some code that generates an image file based off either a
binary file or shared memory.

I figure that I need three functions:

generate_image_from_file # public
generate_image_from_shmem #public
generate_image # private?

The user would call either generate_image_from_file or
generate_image_from_shmem. Once the data has been loaded, both
functions would call generate_image to write the image to a file
somewhere.

Would this be best written as a class inside a module? Or a set of
functions inside a module? I'm not really storing any data, and
there's no point in keeping the object around after the image is
generated.

Thanks,
Joe
 
A

Austin Ziegler

I'm writing some code that generates an image file based off
either a binary file or shared memory.

I figure that I need three functions:

generate_image_from_file # public
generate_image_from_shmem # public
generate_image # private?

The user would call either generate_image_from_file or
generate_image_from_shmem. Once the data has been loaded, both
functions would call generate_image to write the image to a file
somewhere.

Would this be best written as a class inside a module? Or a set of
functions inside a module? I'm not really storing any data, and
there's no point in keeping the object around after the image is
generated.

I think that you're looking at it wrong. The way that I'd do it is
to have generate_image be the public version that accepts either a
binary block of data (e.g., a binary String) or an IO-like object
that responds to #read.

Then, look at putting a shmem wrapper that responds to #read.

-austin
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top