Add documentation about method to describe how it works [ci skip]

This commit is contained in:
Mehmet Emin İNAÇ 2016-02-04 20:03:24 +02:00
parent e22404a8b2
commit e38ced376f
1 changed files with 9 additions and 0 deletions

View File

@ -160,6 +160,15 @@ module ActiveModel
#
# person.errors[:name] # => ["cannot be nil"]
# person.errors['name'] # => ["cannot be nil"]
#
# Note that, if you try to get errors of an attribute which has
# no errors associated with it, this method will instantiate
# an empty error list for it and +keys+ will return an array
# of error keys which includes this attribute.
#
# person.errors.keys # => []
# person.errors[:name] # => []
# person.errors.keys # => [:name]
def [](attribute)
messages[attribute.to_sym]
end