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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -