Skip to content

Instantly share code, notes, and snippets.

@mebezac
Created January 14, 2014 19:22
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 mebezac/8424113 to your computer and use it in GitHub Desktop.
Save mebezac/8424113 to your computer and use it in GitHub Desktop.
Card Value not using global variable, doesn't work. Card Value, using global does work.
#Blackjack
$card_values_hash = {"Ace" => 1, "Two" => 2, "Three" => 3, "Four" => 4, "Five" => 5, "Six" => 6, "Seven" => 7, "Eight" => 8, "Nine" => 9, "Ten" => 10, "Jack" => 10, "Queen" => 10, "King" => 10}
suits = ["Clubs", "Spades", "Diamonds", "Hearts"]
cards = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"]
deck = []
player_hand =[]
deaker_hand =[]
#Create Deck
cards.each do |card|
suits.each do |suit|
deck.push card + " of " + suit
end
end
deck.shuffle!
def card_value (card)
$card_values_hash[card]
end
puts card_value "King"
# prints 10, which is correct.
#Blackjack
card_values_hash = {"Ace" => 1, "Two" => 2, "Three" => 3, "Four" => 4, "Five" => 5, "Six" => 6, "Seven" => 7, "Eight" => 8, "Nine" => 9, "Ten" => 10, "Jack" => 10, "Queen" => 10, "King" => 10}
suits = ["Clubs", "Spades", "Diamonds", "Hearts"]
cards = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"]
deck = []
player_hand =[]
deaker_hand =[]
#Create Deck
cards.each do |card|
suits.each do |suit|
deck.push card + " of " + suit
end
end
deck.shuffle!
def card_value (card)
card_values_hash[card]
end
puts card_value "King"
# Error: card_value.rb:20:in `card_value': undefined local variable or method `card_values_hash' for main:Object (NameError)
# from card_value.rb:22:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment