【发布时间】:2012-05-27 12:33:19
【问题描述】:
我正在使用 RMagick 制作一个项目,该项目会根据大小和颜色生成随机横幅广告。
第一步是这样,但它不能正常工作。我正在使用所谓的三元语句来制作像“#ffffff、#f0f1cd、#123fff”等这样的字符串。
# Generate sixteen random colors
1.upto(16) { |i|
(defined? colors) ? colors << ", #%06x" % (rand(0xffffff)) : colors = "#%06x" % (rand(0xffffff))
}
puts colors.split(',')
期望的结果不正确。我希望它分成一个数组,如: ["#ffffff", "#f0f1cd", "#123fff"]
尽可能采用最优雅的方法。
【问题讨论】: