ruby - Whats wrong with this if statement? Rails -
i building reputation system users points if milestones (10, 100, 1000, ...) archieved. have if statement line:
if (before_points < ((10 || 100 || 1000 || 10000 || 100000 || 1000000))) && (after_points >= ((10 || 100 || 1000 || 10000 || 100000 || 1000000)))
it should return true if points either less 10 or 100 or 1000 ...before, , if points more or equal either 10 or 100 or 1000 ... afterwards.
it works if below 10 before, , more 10 afterwards, , not quite sure if works 100, doesnt work if points below 1000 before , more 1000 afterwards.
is correct way this? better switch/case?
a more compact way it...
[10, 100, 1000, 10000, 100000, 1000000].any?{|n| before_points < n && after_points >= n}
that expression return true
if boundary crossed, or false
otherwise
Comments
Post a Comment