Skip to content

Add AR::Base.base_class? predicate - #32417

Merged
kaspth merged 1 commit into
rails:masterfrom
bogdan:base-class
Apr 2, 2018
Merged

kaspth merged 1 commit into
rails:masterfrom
bogdan:base-class

Conversation

@bogdan

@bogdan bogdan commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown

r? @rafaelfranca

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

Copy link
Copy Markdown
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?

else
# STI subclasses always use their superclass' table.
base.table_name
base_class.table_name

Copy link
Copy Markdown
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
Copy Markdown
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

kaspth commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

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.

5 participants