array : NamedTuple(name: String, age: String) = {name: "crysal", age: "very long"}
(c,d).each() do |a, b|
puts a, b
end
i want to loop over the tuple and get both the key and the value how ?
array : NamedTuple(name: String, age: String) = {name: "crysal", age: "very long"}
(c,d).each() do |a, b|
puts a, b
end
i want to loop over the tuple and get both the key and the value how ?
Your code example is nearly correct
https://crystal-lang.org/api/1.10.1/NamedTuple.html#each(%26)%3ANil-instance-method
some_var : NamedTuple(name: String, age: String) = {name: "crysal", age: "very long"}
some_var.each() do |key, value|
puts key.to_s
puts value
end
The syntax breakdown is:
variable_name : TheTypeYourAreSpecifying = its_default_value
So in your example you named your NamedTuple
as array
, which I think is causing some confusion.