Skip to content

Commit 8944d80

Browse files
authored
Add examples to #slice and #values_at documentation [ci-skip] (rails#50679)
1 parent 90d0dc5 commit 8944d80

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

activemodel/lib/active_model/model.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ module Model
5252
# Returns a hash of the given methods with their names as keys and returned
5353
# values as values.
5454
#
55+
# person = Person.new(id: 1, name: "bob")
56+
# person.slice(:id, :name)
57+
# => { "id" => 1, "name" => "bob" }
58+
#
5559
#--
5660
# Implemented by ActiveModel::Access#slice.
5761

@@ -62,6 +66,10 @@ module Model
6266
#
6367
# Returns an array of the values returned by the given methods.
6468
#
69+
# person = Person.new(id: 1, name: "bob")
70+
# person.values_at(:id, :name)
71+
# => [1, "bob"]
72+
#
6573
#--
6674
# Implemented by ActiveModel::Access#values_at.
6775
end

activerecord/lib/active_record/core.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ def encode_with(coder)
569569
# Returns a hash of the given methods with their names as keys and returned
570570
# values as values.
571571
#
572+
# topic = Topic.new(title: "Budget", author_name: "Jason")
573+
# topic.slice(:title, :author_name)
574+
# => { "title" => "Budget", "author_name" => "Jason" }
575+
#
572576
#--
573577
# Implemented by ActiveModel::Access#slice.
574578

@@ -579,6 +583,10 @@ def encode_with(coder)
579583
#
580584
# Returns an array of the values returned by the given methods.
581585
#
586+
# topic = Topic.new(title: "Budget", author_name: "Jason")
587+
# topic.values_at(:title, :author_name)
588+
# => ["Budget", "Jason"]
589+
#
582590
#--
583591
# Implemented by ActiveModel::Access#values_at.
584592

0 commit comments

Comments
 (0)