Skip to content

Commit

Permalink
Add examples to #slice and #values_at documentation [ci-skip] (#50679) (
Browse files Browse the repository at this point in the history
  • Loading branch information
p8 committed Jan 12, 2024
1 parent fd06c27 commit 620d335
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions activemodel/lib/active_model/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module Model
# 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.

Expand All @@ -62,6 +66,10 @@ module Model
#
# 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
Expand Down
8 changes: 8 additions & 0 deletions activerecord/lib/active_record/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ def encode_with(coder)
# 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.

Expand All @@ -576,6 +580,10 @@ def encode_with(coder)
#
# 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.

Expand Down

0 comments on commit 620d335

Please sign in to comment.