Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
method moved to class
class ColorGenerator
def initialize(color)
@color = color
end
def get_hex(color)
case
when color.length == 1
generated_color = color * 6
when color.length == 2
generated_color = color * 3
when color.length == 3
generated_color = (color[0] * 2) + (color[1] * 2) + (color[2] * 2)
when color.length < 6 && color.length > 3
generated_color = color + ("0" * (6 - color.length))
when color.length > 6
generated_color = color[0..5]
else
generated_color = color
end
return "##{generated_color}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment