Guys for wc, a rubygem I'm writing and that is useful for counting word occurrences in a text, I choose to put 3 parameters in class constructor.
The code is working, but I want to refactor it for niceness. In your experience, it's easier to read/mantain/use as API a class with a constructor with no params and a lot of setters/getters method or a code like this one, with all the params in the constructor?
TIA
Paolo
def initialize(filename, words, hide_list)
if ! filename.nil?
@filename = filename
@occurrences = read
else
@filename = STDIN
@occurrences = feed
end
@hide_list = hide_list
@sorted = Array(occurrences).sort { |one, two| -(one[1] <=> two[1]) }
@words = words
end