|
|
|
|
|
by feca
4472 days ago
|
|
This is actually a very complicated way of achieving the goal. It works, but it's not good from an economic point of view as it is more expensive in computational terms than a simpler OO alternative, which is to pass the size when you instantiate the MegaLotto::Drawing object. For example, compare the proposed solution: MegaLotto.configure do |config|
config.drawing_count = 10
end
MegaLotto::Drawing.new.draw
With the alternative: MegaLotto::Drawing.new(10).draw
If you want to make it extensible, you can use keyword arguments: MegaLotto::Drawing.new(size: 10).draw
The interface and the implementation are simpler, but also the performance is better because there are less method calls. If you look at the code of both implementations, you will find the simpler one easier to understand. As a side effect, you will also get simpler stack traces if anything goes wrong. |
|