New answers tagged

1

Before I answer your question I should point out that: list = to_a if Range is incorrect. Range is a constant and if Range is always true. You probably means if is_a?(Range) which would mean list was undefined in most cases. As a first attempt at solving this I would take the case where an operator is provided and have the method call itself with a block ...


1

It sounds like you're trying to group transactions by member_id and company_id, though in the code you posted you are only grouping by member_id and then overwriting the company with each new transactions' company. If you pass a block to group_by, though, you can group by more than a simple method on the object, for instance you can group by an array of ...


1

Yes, it is generally considered a bad practice because it is considered confusing. Though as you point out it is fairly unlikely to confuse because everything is being set to zeros and the alternative is five lines of repeated code. However I find myself asking why you don't use an array. i.e. freqs = [0, 0, 0, 0, 0] or freqs = Array.new(5, 0) or else ...


1

The big thing I would do here is add some classes to make this more object oriented and easier to read and understand. When I have super complex code that I have trouble understanding and I want to refactor it for readability, I sit down with what the code is supposed to be doing and then write what I wish the code would look like to do that. From there, I ...


Top 50 recent answers are included