I’m making a project with RMagick that generates a random banner advertisement with respect to size and colors.
First step is this, but it does not work properly. I’m using what’s called a ternary statement to make the string like “#ffffff, #f0f1cd, #123fff” etc.
# Generate sixteen random colors
1.upto(16) { |i|
(defined? colors) ? colors << ", #%06x" % (rand(0xffffff)) : colors = "#%06x" % (rand(0xffffff))
}
puts colors.split(',')
The desired outcome is not correct. I want it split into an array like:
[“#ffffff”, “#f0f1cd”, “#123fff”]
In the most elegant approach possible.
You can do this which will be easier:
NOTE: If your are using Ruby 1.9.3, you can use ranges.