Created
August 28, 2014 18:32
-
-
Save alacritythief/f12579fb1a3d7aa3f3e5 to your computer and use it in GitHub Desktop.
A class and sensible constructor for a TV, channel, and show.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TV | |
def initialize(model = nil, size = nil, resolution = nil) | |
if model.nil? | |
@model = ["Sony", "LG", "Samsung", "Vizio"].sample | |
else | |
@model = model | |
end | |
if size.nil? | |
@size = [19, 28, 30, 32, 36, 38, 42, 52].sample | |
else | |
@size = size | |
end | |
if resolution.nil? | |
@resolution = ["420p", "720p", "1080p"].sample | |
else | |
@resolution = resolution | |
end | |
puts "I am a TV! I am a #{@size}\" #{@model} TV, with a #{@resolution} display!" | |
end | |
end | |
class TV_Channel | |
def initialize(number = nil, name = nil) | |
if number.nil? | |
@number = [2, 4, 5, 11, 25, 38].sample | |
else | |
@number = number | |
end | |
if name.nil? | |
@name = ["WGBH", "CBS", "ABC", "NBC", "FOX"].sample | |
else | |
@name = name | |
end | |
puts "I am channel #{@number} - #{@name}!" | |
end | |
end | |
class TV_Show | |
def initialize(name = nil, showtime = nil, rating = nil, channel = nil) | |
if name.nil? | |
@name = ["Oprah", "Two Guys, a Girl, and a Pizza Place", "Friends", "Sienfeld", "Married with Children", "Silicon Valley"].sample | |
else | |
@name = name | |
end | |
if showtime.nil? | |
@showtime = ["5 am", "11 am", "2 pm", "6 pm", "11 pm"].sample | |
else | |
@showtime = showtime | |
end | |
if rating.nil? | |
@rating = ["TV-Y","TV-Y7","TV-G","TV-PG","TV-14","TV-MA"].sample | |
else | |
@rating = rating | |
end | |
if channel.nil? | |
@channel = [2, 4, 5, 11, 25, 38].sample | |
else | |
@channel = channel | |
end | |
puts "#{@name} - Broadcasting at #{@showtime}, on channel #{@channel}, rated #{@rating}!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment