Skip to content

Commit

Permalink
refactor: use public_send instead of zip and to_proc in pluck
Browse files Browse the repository at this point in the history
  • Loading branch information
iberianpig committed Feb 10, 2024
1 parent 9341e7a commit 33f0960
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/active_hash/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def size

def pluck(*column_names)
if column_names.length == 1
all.map(&column_names.first.to_sym)
column_name = column_names.first
all.map { |record| record.public_send(column_name) }
else
# `tap with break` can be replaced with yield_self in Ruby 2.5 or then in Ruby 2.6
column_names.map { |column_name| all.map(&column_name.to_sym) }.tap { |values| break :zip.to_proc.(*values) }
all.map { |record| column_names.map { |column_name| record.public_send(column_name) } }
end
end

Expand Down

0 comments on commit 33f0960

Please sign in to comment.