diff --git a/05_hash_tables/ruby/01_price_of_groceries.rb b/05_hash_tables/ruby/01_price_of_groceries.rb new file mode 100644 index 0000000..9763b25 --- /dev/null +++ b/05_hash_tables/ruby/01_price_of_groceries.rb @@ -0,0 +1,8 @@ +# {} is the same as Hash.new +book = {} +# an apple costs 67 cents +book["apple"] = 0.67 +# milk costs $1.49 +book["milk"] = 1.49 +book["avocado"] = 1.49 +puts book diff --git a/05_hash_tables/ruby/02_check_voter.rb b/05_hash_tables/ruby/02_check_voter.rb new file mode 100644 index 0000000..0832e52 --- /dev/null +++ b/05_hash_tables/ruby/02_check_voter.rb @@ -0,0 +1,16 @@ +# 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")