leading to awkward situations when you only want cactus:
splash = splashlib.new(nil,nil,cactus)
We can simply pass in a definition table that allows for the defaults to be overridden on creation:
splash = splashlib.new{cactus=cactus}
The best thing about this is that it's easy to make forward compatible because the order doesn't matter. For example, let's say you add cactus after the you added background. The following call will work with both versions of the library, even if the cactus variable is not handled.
So instead of having arguments for the new operator like this:
leading to awkward situations when you only want cactus:
We can simply pass in a definition table that allows for the defaults to be overridden on creation:
The best thing about this is that it's easy to make forward compatible because the order doesn't matter. For example, let's say you add
cactus
after the you addedbackground
. The following call will work with both versions of the library, even if thecactus
variable is not handled.and now for a cat