mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add indexer methods for captured arguments
This commit is contained in:
parent
4aaed186c3
commit
29389f1dbf
2 changed files with 30 additions and 0 deletions
|
@ -24,6 +24,26 @@ Spectator.describe Spectator::Arguments do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#[]" do
|
||||
context "with an index" do
|
||||
it "returns a positional argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[0]).to eq(42)
|
||||
expect(arguments[1]).to eq("foo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a symbol" do
|
||||
it "returns a named argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[:bar]).to eq("baz")
|
||||
expect(arguments[:qux]).to eq(123)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_s" do
|
||||
subject { arguments.to_s }
|
||||
|
||||
|
|
|
@ -27,6 +27,16 @@ module Spectator
|
|||
{{@type.name(generic_args: false)}}.capture
|
||||
end
|
||||
|
||||
# Returns the positional argument at the specified index.
|
||||
def [](index : Int)
|
||||
@args[index]
|
||||
end
|
||||
|
||||
# Returns the specified named argument.
|
||||
def [](arg : Symbol)
|
||||
@kwargs[arg]
|
||||
end
|
||||
|
||||
# Constructs a string representation of the arguments.
|
||||
def to_s(io : IO) : Nil
|
||||
return io << "(no args)" if args.empty? && kwargs.empty?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue