diff --git a/lib/rscons/varset.rb b/lib/rscons/varset.rb index 38647cb..2787fec 100644 --- a/lib/rscons/varset.rb +++ b/lib/rscons/varset.rb @@ -143,6 +143,19 @@ module Rscons end end + # Return an array containing the values associated with the given keys. + # + # @param keys [Array] + # Keys to look up in the VarSet. + # + # @return [Array] + # An array containing the values associated with the given keys. + def values_at(*keys) + keys.map do |key| + self[key] + end + end + private # Move all VarSet variables into the copy-on-access list. diff --git a/spec/rscons/varset_spec.rb b/spec/rscons/varset_spec.rb index 32dd574..4e0d479 100644 --- a/spec/rscons/varset_spec.rb +++ b/spec/rscons/varset_spec.rb @@ -199,5 +199,14 @@ module Rscons end end + describe "#values_at" do + it "returns an array of the values associated with the given keys" do + v = VarSet.new({"fuz" => "a string", "foo" => 42, "bar" => :baz, + "qax" => [3, 6], "qux" => {a: :b}}) + expect(v.values_at).to eq [] + expect(v.values_at(*%w[fuz qux qax])).to eq ["a string", {a: :b}, [3, 6]] + end + end + end end