Skip to content

Instantly share code, notes, and snippets.

@radavis
Created August 26, 2013 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radavis/6343389 to your computer and use it in GitHub Desktop.
Save radavis/6343389 to your computer and use it in GitHub Desktop.
class Television
attr_accessor :manufacturer, :hd_compliant, :aspect_ratio, :screen_size
def initialize(manufacturer, hd_compliant, aspect_ratio, screen_size)
@manufacturer = manufacturer
@hd_compliant = hd_compliant
@aspect_ratio = aspect_ratio
@screen_size = screen_size
end
def change_channel(channel)
@channel = channel
end
def to_s
result = "This is a #{@manufacturer} TV"
result += " with an aspect ratio of #{@aspect_ratio}"
result += ", a screen size of #{@screen_size} inches"
result += ", and is tuned to #{@channel.name}" if !@channel.nil?
return result
end
end
class Channel
attr_accessor :name, :channel_number
def initialize(name, channel_number)
@name = name
@channel_number = channel_number
end
end
class Show
attr_accessor :name, :channel, :host, :time
def initialize(name, channel, host, time)
@name = name
@channel = channel
@host = host
@time = time
end
end
tv = Television.new("Sony", true, "16:9", 42)
comedy_central = Channel.new("Comedy Central", 57)
the_daily_show = Show.new("The Daily Show", comedy_central, "Jon Stewart", "6pm")
puts tv
tv.change_channel(comedy_central)
puts tv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment