From 06e908c4e13a0f87f05f6115e13e6f5b8d20d499 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 21 Oct 2012 13:46:41 -0500 Subject: Fix AR::AttributeMethods#[] example [ci skip] --- activerecord/lib/active_record/attribute_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/attribute_methods.rb') diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 008696f6de..ca95329186 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -271,7 +271,7 @@ module ActiveRecord # class Person < ActiveRecord::Base # end # - # person = Person.new(name: 'Francesco', age: '22' + # person = Person.new(name: 'Francesco', age: '22') # person[:name] # => "Francesco" # person[:age] # => 22 def [](attr_name) -- cgit v1.2.3 From bc3f960c0f3b3d88f024969f4606317040cb2332 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 21 Oct 2012 19:20:18 -0500 Subject: improve AR::AttributeMethods documentation [ci skip] --- activerecord/lib/active_record/attribute_methods.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/attribute_methods.rb') 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 empty? (the latter only applies # to objects that respond to empty?, 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?) -- cgit v1.2.3 From ae27acb342c575ce19d5ad78cb13ba23f826fab1 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 21 Oct 2012 20:04:41 -0500 Subject: =?UTF-8?q?read=5Fattribute=20is=20public=C2=A0[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activerecord/lib/active_record/attribute_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/attribute_methods.rb') diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 0118bbd6b6..1dd9a3d45d 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -270,7 +270,7 @@ module ActiveRecord # Returns the value of the attribute identified by attr_name after it has been typecast (for example, # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). - # (Alias for the protected read_attribute method). + # (Alias for read_attribute). # # class Person < ActiveRecord::Base # end -- cgit v1.2.3