From 8944d804ec060ad00a1d310192f0eb3209545f3d Mon Sep 17 00:00:00 2001 From: Petrik de Heus Date: Fri, 12 Jan 2024 11:58:23 +0100 Subject: [PATCH] Add examples to #slice and #values_at documentation [ci-skip] (#50679) --- activemodel/lib/active_model/model.rb | 8 ++++++++ activerecord/lib/active_record/core.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/activemodel/lib/active_model/model.rb b/activemodel/lib/active_model/model.rb index d0d2e586a20..86df469b045 100644 --- a/activemodel/lib/active_model/model.rb +++ b/activemodel/lib/active_model/model.rb @@ -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 diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 7162ed6770b..eaf1ca3cf08 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -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.