generated from LEARNAcademy/ruby-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses-sakaa-rod-shawn.rb
50 lines (41 loc) · 1.84 KB
/
classes-sakaa-rod-shawn.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# For the following ColorPalette challenge use initialize and attr_accessor methods in your class.
## As a developer, I can create a class called ColorPalette.
## As a developer, I can create three instances (objects) of class ColorPalette.
## e.g green = ColorPalette.new
## As a developer, I can initialize each instance of the class ColorPalette with three colors.
## e.g. green = ColorPalette.new('Chartreuse', 'Kelly', 'Seafoam')
# As a developer, I can print the value of each individual color.
# As a developer, I can create a method called all_colors that when called will print a sentence telling me the three colors of a given palette.
# As a developer, I can change one or more colors of a given palette.
class ColorPalette
attr_accessor :color1, :color2, :color3
def initialize (color1 = 'red', color2 = 'blue', color3 = 'yellow')
@color1 = color1
@color2 = color2
@color3 = color3
end
def print_individual_colors
puts "color1: #{@color1}"
puts "color2: #{@color2}"
puts "color3: #{@color3}"
end
def all_colors
"Variations of #{@color1}, #{@color2}, and #{@color3} are available."
end
def change_colors(new_color1, new_color2, new_color3)
@color1 = new_color1
@color2 = new_color2
@color3 = new_color3
puts "Colors changed to #{new_color1}, #{new_color2}, #{new_color3}."
end
end
default_palette = ColorPalette.new
default_palette.print_individual_colors
default_palette.change_colors('Cinnabar', 'Saffron', 'Goldenrod')
puts default_palette.all_colors
# green.change_colors('Lime', 'Forest Green', 'Mint')
# green.print_individual_colors
# puts green.all_colors
# (red = 'Cinnabar','Vermilion', 'Amaranth')
# blue = ColorPalette.new('Cerulean', 'Saffron', 'Indigo')
# yellow = ColorPalette.new('Goldenrod','Aureolin', 'Sarcoline' )