Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AR::Base.base_class? predicate #32417

Merged
merged 1 commit into from Apr 2, 2018
Merged

Add AR::Base.base_class? predicate #32417

merged 1 commit into from Apr 2, 2018

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Apr 2, 2018

Summary

base_class? can be handy addition to the base_class which is the same as self == base_class.
In my project klass.base_class == klass is 50% the case of the base_class. The same is actual for AR internally.

@rails-bot
Copy link

r? @rafaelfranca

(@rails-bot has picked a reviewer for you, use r? to override)

@@ -12,7 +12,7 @@ def type; :integer; end
def setup
@klass = Class.new(Class.new { def self.initialize_generated_modules; end }) do
def self.superclass; Base; end
def self.base_class; self; end
def self.base_class?; self; end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this now return true instead of self?

@@ -513,7 +512,7 @@ def compute_table_name
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{full_table_name_suffix}"
else
# STI subclasses always use their superclass' table.
base.table_name
base_class.table_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a performance hot spot? Assuming the local variable is there for a reason 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not: the result of this method is cached inside @table_name and L512 with its string construction is way slower than the else case.

@kaspth kaspth merged commit c9ad88f into rails:master Apr 2, 2018
@kaspth
Copy link
Contributor

kaspth commented Apr 2, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants