aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-21 19:20:18 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-10-21 19:20:18 -0500
commitbc3f960c0f3b3d88f024969f4606317040cb2332 (patch)
tree89d2d4ffd49da6d6fb94bc52ec3b0ede14b33022 /activerecord/lib/active_record/attribute_methods.rb
parent7fbb21dc802c9eb96d30c6231e2b3dc473dbe9dd (diff)
downloadrails-bc3f960c0f3b3d88f024969f4606317040cb2332.tar.gz
rails-bc3f960c0f3b3d88f024969f4606317040cb2332.tar.bz2
rails-bc3f960c0f3b3d88f024969f4606317040cb2332.zip
improve AR::AttributeMethods documentation [ci skip]
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index ca95329186..0118bbd6b6 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -215,10 +215,10 @@ module ActiveRecord
# person = Person.create!(name: 'David Heinemeier Hansson ' * 3)
#
# person.attribute_for_inspect(:name)
- # # => '"David Heinemeier Hansson David Heinemeier Hansson D..."'
+ # # => "\"David Heinemeier Hansson David Heinemeier Hansson D...\""
#
# person.attribute_for_inspect(:created_at)
- # # => '"2009-01-12 04:48:57"'
+ # # => "\"2012-10-22 00:15:07\""
def attribute_for_inspect(attr_name)
value = read_attribute(attr_name)
@@ -234,14 +234,18 @@ module ActiveRecord
# Returns +true+ if the specified +attribute+ has been set by the user or by a
# database load and is neither +nil+ nor <tt>empty?</tt> (the latter only applies
# to objects that respond to <tt>empty?</tt>, most notably Strings). Otherwise, +false+.
+ # Note that it always returns +true+ with boolean attributes.
#
- # class Person < ActiveRecord::Base
+ # class Task < ActiveRecord::Base
# end
#
- # person = Person.new(name: '')
- # person.attribute_present?(:name) # => false
+ # person = Task.new(title: '', is_done: false)
+ # person.attribute_present?(:title) # => false
+ # person.attribute_present?(:is_done) # => true
# person.name = 'Francesco'
- # person.attribute_present?(:name) # => true
+ # person.is_done = true
+ # person.attribute_present?(:title) # => true
+ # person.attribute_present?(:is_done) # => true
def attribute_present?(attribute)
value = read_attribute(attribute)
!value.nil? && !(value.respond_to?(:empty?) && value.empty?)