From 2c0729d8cb13100ea576337ebb7703320203c548 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 23 Apr 2019 22:26:17 +0900 Subject: Re-organize `init_internals` * Avoid duplicated `@new_record` assignment * Extract `define_attribute_methods` into `init_internals` --- activerecord/lib/active_record/core.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/core.rb') diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 351865dfbc..28bd7f8cdc 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -316,7 +316,7 @@ module ActiveRecord # # Instantiates a single new object # User.new(first_name: 'Jamie') def initialize(attributes = nil) - self.class.define_attribute_methods + @new_record = true @attributes = self.class._default_attributes.deep_dup init_internals @@ -353,12 +353,10 @@ module ActiveRecord # +attributes+ should be an attributes object, and unlike the # `initialize` method, no assignment calls are made per attribute. def init_with_attributes(attributes, new_record = false) # :nodoc: - init_internals - @new_record = new_record @attributes = attributes - self.class.define_attribute_methods + init_internals yield self if block_given? @@ -574,9 +572,10 @@ module ActiveRecord @destroyed = false @marked_for_destruction = false @destroyed_by_association = nil - @new_record = true @_start_transaction_state = nil @transaction_state = nil + + self.class.define_attribute_methods end def initialize_internals_callback -- cgit v1.2.3