[code="ruby"]max =2.to_f, min = 0.8.to_f, size = 1
fonts = [max, min]
if level == 1
size = 1
elsif level == 2
size = fonts[index]
else
(0...level-2).each do
fonts << ((max-min) / (3 - 1) + min)
end
size = fonts.sort[index]
end[/code]
这段code会报错,Can't convert Float to Array
把max,min全部用数字替换就不会,为什么呢?
请这样写:
max = 2.0
min = 0.8
size = 1
或者这样写:
max, min, size = 2.0, 0.8, 1
或者这样写:
max = 2.0; min = 0.8; size = 1
这是改错题吗?
:roll:
index从哪里来?
注意,
max = 2.to_f, min = 0.8.to_f, size = 1
相当于
max = [color=red][[/color]2.to_f, min = 0.8.to_f, size = 1[color=red]][/color]
结论:逗号不是这么用的。