Add indexer methods for captured arguments

This commit is contained in:
Michael Miller 2022-07-10 17:38:17 -06:00
parent 4aaed186c3
commit 29389f1dbf
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
2 changed files with 30 additions and 0 deletions

View file

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