Skip to content

Instantly share code, notes, and snippets.

@croaky
Forked from harlow/use_factory_method.rb
Last active December 15, 2015 02:09
Show Gist options
  • Save croaky/5185403 to your computer and use it in GitHub Desktop.
Save croaky/5185403 to your computer and use it in GitHub Desktop.
class Customer
def initialize(attrs = {})
@id = attrs[:id]
@country = attrs[:country]
end
def tax_code
TaxCodes[@country].call(@id)
rescue
raise "Tax codes for #{@country} not supported"
end
end
TaxCodes = {
'Brazil' => lambda { |id| "#{id}-BR" },
'USA' => lambda { |id| "US-#{id}" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment