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

Conversation

Projects
None yet
5 participants
@bogdan
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Apr 2, 2018

r? @rafaelfranca

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

rails-bot commented Apr 2, 2018

r? @rafaelfranca

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

Show outdated Hide outdated activerecord/test/cases/attribute_methods/read_test.rb Outdated
@@ -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

This comment has been minimized.

@kaspth

kaspth Apr 2, 2018

Member

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

@kaspth

kaspth Apr 2, 2018

Member

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

This comment has been minimized.

@bogdan

bogdan Apr 2, 2018

Contributor

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.

@bogdan

bogdan Apr 2, 2018

Contributor

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

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Apr 2, 2018

Member

Thanks!

Member

kaspth commented Apr 2, 2018

Thanks!

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