【问题标题】:How to make an array of a composed type in Crystal?如何在 Crystal 中制作组合类型的数组?
【发布时间】:2022-06-24 06:21:45
【问题描述】:

我在尝试

class Output
  alias Type = String | Array(Output) | Hash(Symbol, Output)
  
  getter raw

  def initialize(@raw : Type)
  end
end

hash = Output.new({ :a => Output.new("1") })
array = Output.new([hash.raw])

【问题讨论】:

    标签: crystal-lang


    【解决方案1】:

    Type 包括 Array(Output) 所以我需要传递输出而不是原始类型:

    array = Output.new([hash])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2018-08-07
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多