Why is this not a valid operation?
def get_highest_bar()
#co开发者_如何学Gonvert string to integer array
data = @data.split(",")
return Integer(data.max)
end
#rounds up to nearest factor of 100
def round_up(n)
return 100 if n < 100
return (n+50)/100*100
end
@axis_range_prefix = "chxr="
@y_axis_index = "1"
#error here:
axis_range = @axis_range_prefix + [@y_axis_index, "0", highest_bar.to_s()].join(",")
You don't need the get_ prefix in your get_highest_bar method. That's a java habit, isn't it? The fact that you called it highest_bar later proves that a good name reflects what the result is, not the action you took to get it.
Parens after the method definition are optional and not idiomatic ruby.
The
return Integer(data.max)
probably doesn't do what you think. If@data
contained "1,10,2" the max is 2, because they're being compared as strings.
Rewritten method:
def highest_bar
@data.split(",").map(&:to_i).max
end
You have a typo, highest_bar is undefined. You should call get_highest_bar(). I.e.
axis_range = @axis_range_prefix + [@y_axis_index, "0", get_highest_bar.to_s()].join(",")
精彩评论