Skip to content

Instantly share code, notes, and snippets.

@NILID
Created September 27, 2019 11:43
Show Gist options
  • Save NILID/b7e8fd3f72637e245091082a72ba7b09 to your computer and use it in GitHub Desktop.
Save NILID/b7e8fd3f72637e245091082a72ba7b09 to your computer and use it in GitHub Desktop.
Generate a random hex color, or with fixing anyone color
class RandomColor
def self.get_random
rand(255)
end
def self.color_hex(options = {})
default = { red: get_random, green: get_random, blue: get_random }
options = default.merge(options)
'#%X%X%X' % options.values
end
end
@NILID
Copy link
Author

NILID commented Sep 27, 2019

full random colour

RandomColor.color_hex() => #299D3D
RandomColor.color_hex() => #C0E92D

freeze any color

RandomColor.color_hex(red: 100) => #644BD6
RandomColor.color_hex(red: 100) => #6488D9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment