Skip to content

Instantly share code, notes, and snippets.

@t0d0r
Created November 20, 2012 11:40
Show Gist options
  • Save t0d0r/4117441 to your computer and use it in GitHub Desktop.
Save t0d0r/4117441 to your computer and use it in GitHub Desktop.
sample ruby class using Stuct
# TODO: finish this
class Colors
attr_accessor :color
ColorAttr = Struct.new(:name, :hex)
{
:silver => ColorAttr.new("silver", "ff0000"),
:blue => ColorAttr.new("blue", "ff0000"),
:black => ColorAttr.new("black", "ff0000"),
:white => ColorAttr.new("white", "ff0000"),
:red => ColorAttr.new("red", "ff0000"),
:green => ColorAttr.new("green", "00ff00"),
:other => ColorAttr.new("other", "00ff00"),
}
def initialize
@color = {
:silver => ColorAttr.new("silver", "ff0000"),
:blue => ColorAttr.new("blue", "ff0000"),
:black => ColorAttr.new("black", "ff0000"),
:white => ColorAttr.new("white", "ff0000"),
:red => ColorAttr.new("red", "ff0000"),
:green => ColorAttr.new("green", "00ff00"),
:other => ColorAttr.new("other", "00ff00"),
}
end
def list
color.keys
end
def random_pick
k = color.keys
k[rand(k.size)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment