You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The FlipFlop cop documentation from 684d835 states:
# @example
# # bad
# (1..20).each do |x|
# puts x if (x == 5) .. (x == 10)
# end
#
# # good
# (1..20).each do |x|
# puts x if (x >= 5) && (x <= 10)
# end
The suggested better alternative however does something completely different than the bad example for a different kind of dataset, for example:
irb(main):084:0> [5,20,15,10,5].each { |x| puts x if (x >= 5) && (x <= 10) }5105irb(main):085:0> [5,20,15,10,5].each { |x| puts x if (x == 5)..(x == 10) }52015105
The 'good' example is definitely wrong here, but FlipFlop is really weird and rare operator and I'm not even sure what alternative can be put in a 'good' example.
Your suggested alternative is correct but in fact, it's just an algorithm rather than a good practice example. I'm not sure that it's the best option to suggest here.
Maybe it will sound too much, but maybe it's not be a bad idea to just suggest not to use it at all? I mean without 'good' example.
Check out this article about how rare this operator is:
about 1 in every 23 million lines of Ruby code, or 1-in-10 million to round to an order of magnitude
The FlipFlop cop documentation from 684d835 states:
The suggested better alternative however does something completely different than the bad example for a different kind of dataset, for example:
Maybe the examples should be something like:
And:
The good one does not look that hot either, but maybe someone can come up with a prettier solution.
The text was updated successfully, but these errors were encountered: