Skip to content

Commit

Permalink
Only use and/or keywords for control flow (#12)
Browse files Browse the repository at this point in the history
Using `and` and `or` for anything other than control flow has too often lead to
subtle bugs.
  • Loading branch information
bquorning authored and ddnexus committed May 27, 2018
1 parent 26bb29c commit 39c5470
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pagy.rb
Expand Up @@ -22,7 +22,7 @@ def self.root; Pathname.new(__FILE__).dirname end

# merge and validate the options, do some simple aritmetic and set the instance variables
def initialize(vars)
@vars = VARS.merge(vars.delete_if{|k,v| v.nil? or v == '' }) # default vars + cleaned instance vars
@vars = VARS.merge(vars.delete_if{|k,v| v.nil? || v == '' }) # default vars + cleaned instance vars
{ count:0, items:1, outset:0, page:1 }.each do |k,min| # validate core variables
(@vars[k] && instance_variable_set(:"@#{k}", @vars.delete(k).to_i) >= min) \
or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}")
Expand Down

0 comments on commit 39c5470

Please sign in to comment.