Add Rscons::VarSet#values_at - close #45
This commit is contained in:
parent
89562c584a
commit
099d26f33c
@ -143,6 +143,19 @@ module Rscons
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
# Move all VarSet variables into the copy-on-access list.
|
# Move all VarSet variables into the copy-on-access list.
|
||||||
|
@ -199,5 +199,14 @@ module Rscons
|
|||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user