class << self
def solve problem
...
end
private
def helper1
...
end
def helper2
...
end
end
end
puts Sudoku.solve “15000…00358”
[4]
module Sudoku
class << self
def solve problem
...
end
private
def helper1
...
end
def helper2
...
end
end
end
end
puts Sudoku.solve “15000…00358”
I’m a big fan of Object-orientation.
But if the object’s life-span is as short as Solver.new(problem).solve,
I’m really hesitant to create an object when a simple method call will
do.
Am I thinking of a worthless subjective thing?
Do you have any criteria about going for object/class/module/top-level
methods?
I’m a big fan of Object-orientation. But if the object’s life-span is as
short as Solver.new(problem).solve, I’m really hesitant to create an object
when a simple method call will do. Am I thinking of a worthless subjective
thing?
Do you have any criteria about going for object/class/module/top-level
methods?
in all seriousness this is precisely why i just wrote the prototype
library - i was just facing this question (again) yesterday and couldn’t
stand
it anymore. now i can write
solver = prototype{ @some_instance_var
def solve
something @some_instance_var
end
def something arg
end
}
eh voila!
check it out and let me know what you think - it really is designed for
exactly this purpose.
btw - i’ll be making a new release later today which is cleaned up a lot
but
only adds one small new feature so the current one, though messy, should
be
fine to play with regarding functionality.