Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Forked from mperham/gist:1379464
Last active December 10, 2015 08:18
Show Gist options
  • Save boy-jer/4406775 to your computer and use it in GitHub Desktop.
Save boy-jer/4406775 to your computer and use it in GitHub Desktop.
// Correction to this article: http://kresimirbojcic.com/2011/11/19/dependency-injection-in-ruby.html
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