Add examples to #slice and #values_at documentation [ci-skip] (#50679)

This commit is contained in:
Petrik de Heus 2024-01-12 11:58:23 +01:00 committed by GitHub
parent 90d0dc5961
commit 8944d804ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -52,6 +52,10 @@ module ActiveModel
# Returns a hash of the given methods with their names as keys and returned
# values as values.
#
# person = Person.new(id: 1, name: "bob")
# person.slice(:id, :name)
# => { "id" => 1, "name" => "bob" }
#
#--
# Implemented by ActiveModel::Access#slice.
@ -62,6 +66,10 @@ module ActiveModel
#
# Returns an array of the values returned by the given methods.
#
# person = Person.new(id: 1, name: "bob")
# person.values_at(:id, :name)
# => [1, "bob"]
#
#--
# Implemented by ActiveModel::Access#values_at.
end

View File

@ -569,6 +569,10 @@ module ActiveRecord
# Returns a hash of the given methods with their names as keys and returned
# values as values.
#
# topic = Topic.new(title: "Budget", author_name: "Jason")
# topic.slice(:title, :author_name)
# => { "title" => "Budget", "author_name" => "Jason" }
#
#--
# Implemented by ActiveModel::Access#slice.
@ -579,6 +583,10 @@ module ActiveRecord
#
# Returns an array of the values returned by the given methods.
#
# topic = Topic.new(title: "Budget", author_name: "Jason")
# topic.values_at(:title, :author_name)
# => ["Budget", "Jason"]
#
#--
# Implemented by ActiveModel::Access#values_at.