change param name to improve documentation #6829

Merged
merged 1 commit into from Jun 22, 2012

Conversation

Projects
None yet
3 participants
@frodsan
Contributor

frodsan commented Jun 22, 2012

The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

# Returns +true+ if the error messages include an error for the given
# +attribute+, +false+ otherwise.
#
#   person.errors.messages # => { :name => ["can not be nil"] }
#   person.errors.include?(:name) # => true
#   person.errors.include?(:age)  # => false
def include?(attribute)
  (v = messages[attribute]) && v.any?
end
Francesco Rodriguez
change param name to improve documentation
The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

    # Returns +true+ if the error messages include an error for the given
    # +attribute+, +false+ otherwise.
    #
    #   person.errors.messages # => { :name => ["can not be nil"] }
    #   person.errors.include?(:name) # => true
    #   person.errors.include?(:age)  # => false
    def include?(attribute)
      (v = messages[attribute]) && v.any?
    end

rafaelfranca added a commit that referenced this pull request Jun 22, 2012

Merge pull request #6829 from frodsan/misunderstood_param
change param name to improve documentation

@rafaelfranca rafaelfranca merged commit a232831 into rails:master Jun 22, 2012

@frodsan

This comment has been minimized.

Show comment
Hide comment
@frodsan

frodsan Jun 22, 2012

Contributor

More examples in the same module:

  • def add(attribute, message = nil, options = {})
  • def [](attribute)
  • def []=(attribute, error)
  • ...
Contributor

frodsan commented Jun 22, 2012

More examples in the same module:

  • def add(attribute, message = nil, options = {})
  • def [](attribute)
  • def []=(attribute, error)
  • ...
@splattael

This comment has been minimized.

Show comment
Hide comment
@splattael

splattael Jun 25, 2012

Contributor

In the docs +error+ should read +attribute+

In the docs +error+ should read +attribute+

This comment has been minimized.

Show comment
Hide comment
@splattael

splattael Jun 25, 2012

Contributor

Uh oh, I didn't see that commit. Sorry for the noise :-(

Contributor

splattael replied Jun 25, 2012

Uh oh, I didn't see that commit. Sorry for the noise :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment