Skip to content

Instantly share code, notes, and snippets.

@crazymykl
Last active July 24, 2019 15:12
Show Gist options
  • Save crazymykl/4615e205ae812227a9245dd131ff80f1 to your computer and use it in GitHub Desktop.
Save crazymykl/4615e205ae812227a9245dd131ff80f1 to your computer and use it in GitHub Desktop.
Flagged base class
# This works because the first constant classes are assigned to automagically becomes their main name
ApplicationRecord = if feature_flag?
Class.new(ActiveRecord::Base) do
# implementation
end
else
ActiveRecord::Base
end
=begin
[20] pry(main)> def feature_flag?; false; end
[21] pry(main)> class Quux < ApplicationRecord; end
=> nil
[22] pry(main)> Quux.superclass
=> ActiveRecord::Base
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment