Skip to content

Instantly share code, notes, and snippets.

@cody-code-wy
Created May 25, 2016 20:45
Show Gist options
  • Save cody-code-wy/4f73b1ecc1a7da0803a4316de6c00824 to your computer and use it in GitHub Desktop.
Save cody-code-wy/4f73b1ecc1a7da0803a4316de6c00824 to your computer and use it in GitHub Desktop.
@states = {
OR: {name:'Oregon',city:["Portland","Bend"],tax:1},
FL: {name:'Florida',city:["Orlando","Miami"],tax:0.9},
CA: {name: 'California',city:["Los Angeles"],tax:0.2},
NY: {name:'New York',city:["New York","Albany"],tax:0},
MI: {name:'Michigan',city:["Ann Arbor","Jackson"],tax:0.4}
}
@states[:TX] = {name:"Texas",city:["Dallas","Huston","Austen"],tax:8}
@states[:WA] = {name:"Washington",city:["Spokan","Seattle"],tax:0.1}
def describe_state(state)
return "State does not exist" unless @states[state.to_sym]
return "#{state} is for #{@states[state.to_sym][:name]}. It has #{@states[state.to_sym][:city].count} major cities: #{@states[state.to_sym][:city].join(", ")}"
end
def calculate_tax(state,ammount)
return "State does not exist" unless @states[state.to_sym]
return "%.2f" % (ammount * @states[state.to_sym][:tax])
end
puts "Describe using string input"
@states.each { |k,_| puts describe_state(k.to_s) }
puts "Describe using symbol input"
@states.each { |k,_| puts describe_state(k.to_sym) }
puts "Calculate tax on $1 with string input"
@states.each { |k,_| puts "#{k}: #{calculate_tax(k.to_s,1)}" }
puts "Calculate tax on $1 wih symbol input"
@states.each { |k,_| puts "#{k}: #{calculate_tax(k.to_sym,1)}" }
puts "Describe nonexistant state 'bc'"
puts describe_state("bc")
puts "Describe nonexistant state :bc"
puts describe_state(:bc)
puts "Calculate tax on $1 in nonexistant state 'bc'"
puts calculate_tax("bc",1)
puts "Calculate tax on $1 in nonexistant state :bc"
puts calculate_tax(:bc,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment