diff options
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index a5eb18246f..4705f129f2 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -456,26 +456,23 @@ module ActiveRecord # Takes a PP and prettily prints this record to it, allowing you to get a nice result from `pp record` # when pp is required. def pretty_print(pp) - if self.class.instance_method(:inspect).owner != ActiveRecord::Base.instance_method(:inspect).owner - pp.text inspect - else - pp.object_address_group(self) do - if defined?(@attributes) && @attributes - column_names = self.class.column_names.select { |name| has_attribute?(name) || new_record? } - pp.seplist(column_names, proc { pp.text ',' }) do |column_name| - column_value = read_attribute(column_name) - pp.breakable ' ' - pp.group(1) do - pp.text column_name - pp.text ':' - pp.breakable - pp.pp column_value - end - end - else + return super if custom_inspect_method_defined? + pp.object_address_group(self) do + if defined?(@attributes) && @attributes + column_names = self.class.column_names.select { |name| has_attribute?(name) || new_record? } + pp.seplist(column_names, proc { pp.text ',' }) do |column_name| + column_value = read_attribute(column_name) pp.breakable ' ' - pp.text 'not initialized' + pp.group(1) do + pp.text column_name + pp.text ':' + pp.breakable + pp.pp column_value + end end + else + pp.breakable ' ' + pp.text 'not initialized' end end end @@ -564,5 +561,9 @@ module ActiveRecord @attributes = @attributes.dup end end + + def custom_inspect_method_defined? + self.class.instance_method(:inspect).owner != ActiveRecord::Base.instance_method(:inspect).owner + end end end |