Skip to content

Instantly share code, notes, and snippets.

@jilucev
Created March 6, 2014 04:57
Show Gist options
  • Save jilucev/9382912 to your computer and use it in GitHub Desktop.
Save jilucev/9382912 to your computer and use it in GitHub Desktop.
Cool beans!
states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
states[:AR] = "Arkansas"
states[:HA] = "Hawaii"
cities = {
OR: ["Portland", "Eugene"],
FL: ["Alford", "Baldwin"],
CA: ["SanFrancisco", "Los Angeles"],
NY: ["Manhattan", "Abalone"],
MI: ["Detroit", "Kalamazoo"],
AR: ["Conway", "Rogers"],
HA: ["Maui", "Honolulu"],
}
taxes = {
OR: 7.5,
FL: 80,
CA: 3.6,
NY: 5.5,
MI: 9,
AR: 15,
HA: 4,
}
def describe_state(code, states, cities)
states.each do |key, value|
if code == key
puts "#{key} is for #{value}"
end
end
cities.each do |key, value|
if code == key
puts "It has two major cities: " + "#{value.join(" and ")}."
end
end
end
def calculate_tax(taxes, state_code, total_purchase)
tax_amount = taxes[state_code] * total_purchase
return tax_amount/100
end
def find_state_for_city(state_cities, city)
#puts (cities.index(city))
state_cities.each do |state, cities|
return state if cities.include?(city)
end
end
describe_state(:CA, states, cities)
calculate_tax(taxes, :CA, 123.49)
find_state_for_city(cities, "Portland")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment