Project

General

Profile

Feature #12523

`Object#values_at`

Added by sawa (Tsuyoshi Sawada) about 3 years ago. Updated about 3 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:76161]

Description

It might be convenient to have a method that returns multiple attributes of an object.

class A
  attr_accessors :foo, :bar, :baz

  def initialize foo, bar, baz; @foo, @bar, @baz = foo, bar, baz end
end

A.new("a", "b", "c")
A.values_at(:baz, :foo) # => ["c", "a"]

History

Updated by sawa (Tsuyoshi Sawada) about 3 years ago

It might be convenient to have a method that returns multiple attributes of an object.

class A
  attr_accessors :foo, :bar, :baz

  def initialize foo, bar, baz; @foo, @bar, @baz = foo, bar, baz end
end

a = A.new("a", "b", "c")
a.values_at(:baz, :foo) # => ["c", "a"]

Updated by shyouhei (Shyouhei Urabe) about 3 years ago

I'm not that strongly against it, but wonder if it has actual usage where it is convenient. Do you have any use cases?

Also available in: Atom PDF