Add Rscons::VarSet#values_at - close #45

This commit is contained in:
Josh Holtrop 2017-08-03 15:54:24 -04:00
parent 89562c584a
commit 099d26f33c
2 changed files with 22 additions and 0 deletions

View File

@ -143,6 +143,19 @@ module Rscons
end
end
# Return an array containing the values associated with the given keys.
#
# @param keys [Array<String, Symbol>]
# 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.

View File

@ -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