Skip to content

Instantly share code, notes, and snippets.

@mathie
Created June 15, 2009 17:13
Show Gist options
  • Save mathie/130220 to your computer and use it in GitHub Desktop.
Save mathie/130220 to your computer and use it in GitHub Desktop.
class Neat < ActiveRecord::Base
class << self
def new(params = {})
if self == Search
if params.with_indifferent_access.include?(:evil_quota)
Evil.new(params)
elsif params.include?(:doom_level)
Doomed.new(params)
else
super
end
else
super
end
end
end
end
class Evil < Neat
end
class Doomed < Neat
end
n = Neat.new(:evil_quota => 3.75)
n.is_a?(Neat) # => true
n.is_a?(Evil) # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment