Browse files

Add better docs for ActiveRecord::Base#attribute_for_inspect

  • Loading branch information...
1 parent 10a35b0 commit 73db43527d162fdf95665d88589f7ab6d17a17fa @chrisk chrisk committed Jan 11, 2009
Showing with 12 additions and 1 deletion.
  1. +12 −1 activerecord/lib/active_record/base.rb
View
13 activerecord/lib/active_record/base.rb
@@ -2739,7 +2739,18 @@ def attributes_before_type_cast
end
end
- # Format attributes nicely for inspect.
+ # Returns an <tt>#inspect</tt>-like value for the value of the attribute
+ # referred to by +attr_name+. Strings are elided after 50 characters,
+ # and Dates and Times are returned in the <tt>:db</tt> format. Other
+ # attributes return the value of <tt>#inspect</tt> normally.
+ #
+ # person = Person.create!(:name => "David Heinemeier Hansson " * 3)
+ #
+ # person.attribute_for_inspect(:name)
+ # # => '"David Heinemeier Hansson David Heinemeier Hansson D..."'
+ #
+ # person.attribute_for_inspect(:created_at)
+ # # => '"2009-01-12 04:48:57"'
def attribute_for_inspect(attr_name)
value = read_attribute(attr_name)

0 comments on commit 73db435

Please sign in to comment.