【发布时间】:2019-12-19 22:33:17
【问题描述】:
在下面的代码中,命名参数必须重复,有没有办法缩短表达式?
struct Figure
getter id : String
getter hash : String
getter title : String
def initialize(@id, @hash, @title)
end
end
id = "Figure 1", hash = "123", title = "Some figure"
Figure.new id: id, hash: hash, title: title
类似于下面的代码,但保持命名不是位置?
Figure.new id, hash, title
或许
Figure.new{ id, hash, title }
【问题讨论】:
标签: crystal-lang