Skip to content

Instantly share code, notes, and snippets.

@Sobak
Created March 23, 2016 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sobak/e0fae5f3df3f062c6b6c to your computer and use it in GitHub Desktop.
Save Sobak/e0fae5f3df3f062c6b6c to your computer and use it in GitHub Desktop.
class PeselValidate
@@weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1]
def initialize(str1)
@pesel = str1
end
def validate
numbers = @pesel.split(//).map(&:to_i)
sum = 0
numbers.each_with_index do |number, position|
sum += number * @@weights[position]
end
sum % 10 == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment