Skip to content

Instantly share code, notes, and snippets.

@sanakm
Created March 2, 2016 23:18
Show Gist options
  • Save sanakm/3d06f69fc6f7039b4628 to your computer and use it in GitHub Desktop.
Save sanakm/3d06f69fc6f7039b4628 to your computer and use it in GitHub Desktop.
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan',
}
@states.merge! ({TX: "Texas"})
@states.merge! ({KY: "Kentucky"})
p @states
@cities = {
OR: ['Eugene','Bend'],
FL: ['Miami','Key West'],
CA: ['LA','SF'],
NY: ['NYC','Syracuse'],
MI: ['Detroit','Flint'],
TX: ['Houston','Dallas'],
KY: ['Frankfort','Lexington']
}
p @cities
def describe_state(code)
state_code = code.to_sym
long_code = @states[state_code]
cities = @cities[state_code]
p "#{state_code} stands for #{long_code}. #{state_code} has two cities: #{cities.join(",")}"
end
describe_state("TX")
@taxes = {
OR: 7,
FL: 8,
CA: 9,
NY: 6,
MI: 4,
TX: 5,
KY: 10,
}
def calculate_tax(code, dollar_amount)
state_code = code.to_sym
dollar = dollar_amount
tax_rate = @taxes[state_code]
tax_amount = (tax_rate* 0.01) * dollar
p "#{state_code} has a tax of #{tax_rate}%. You bought something for $#{dollar}, so you will be paying an extra $#{tax_amount.round(2)} in taxes"
end
calculate_tax("OR", 100)
def find_state_for_city(city_to_find)
@cities.each do |state, cities_array|
cities_array.each do |city|
if city == city_to_find
puts "#{city} is in #{state}"
end
end
end
end
find_state_for_city("Houston")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment