Skip to content

Instantly share code, notes, and snippets.

@haileys
Created June 23, 2014 18:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haileys/46a69db898943a659f98 to your computer and use it in GitHub Desktop.
Save haileys/46a69db898943a659f98 to your computer and use it in GitHub Desktop.
class MyBase < ActiveRecord::Base
def self.compute_type(type_name)
case type_name
when "MyBase"; MyBase
when "Foo"; Foo
when "Bar"; Bar
else super
end
end
end
class Foo < MyBase
end
class Bar < MyBase
end
@tompave
Copy link

tompave commented Jun 24, 2014

Anyway, ActiveSupport::Dependencies.constantize(type_name) isn't so bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment