class Command
@command : String
@target : String
@options : Hash(Symbol, String)
def initialize(options = {} of Symbol => String)
puts options
@command = options["command"]
@target = options["target"]
@options = options["options"]
end
end
Command.new({
command: "one",
target: "two",
options: {message: "he"}
})
Hi Miguel,
The expression
{
command: "one",
target: "two",
options: {message: "he"}
}
is of type NamedTuple(command: String, target: String, options: NamedTuple(message: String))
And the expression
{
:command => "one",
:target => "two",
:options => {:message => "he"}
}
is of type Hash(Symbol, Hash(Symbol, String) | String)
In this case, since each key may have different value types associated I would recommend to take advantage of NamedTuples since they will preserve the type information for each key.
I hope this help to move forward.
--
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/544cc844-c925-451a-ab4c-54a11b1aa53f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.