Files
grokking_algorithms/05_hash_tables/ruby/02_check_voter.rb
2016-03-03 15:43:19 +01:00

17 lines
351 B
Ruby

# in order to be accessible from within the check_voter function
# voted has to be an instance variable (or global / class)
@voted = {}
def check_voter(name)
if @voted.key?(name) && @voted[name]
puts "kick them out!"
else
@voted[name] = true
puts "let them vote!"
end
end
check_voter("tom")
check_voter("mike")
check_voter("mike")