Skip to content

Instantly share code, notes, and snippets.

@oshchyhol
Forked from mperham/gist:1379464
Created November 20, 2013 13:06
Show Gist options
  • Save oshchyhol/7562850 to your computer and use it in GitHub Desktop.
Save oshchyhol/7562850 to your computer and use it in GitHub Desktop.
class TaxCode
GENERATORS = {
:us => lambda { |id| "US-#{id}" },
:br => lambda { |id| "#{id + 9}-BRA" },
}
def self.generate(code, id)
gen = GENERATORS[code] || raise ArgumentError, "No generator for country #{code}"
gen.call(id)
end
end
class User
attr_accessor :country_code
attr_accessor :id
def tax_code
TaxCode.generate(country_code, id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment