Created
May 16, 2011 22:09
-
-
Save onewland/975489 to your computer and use it in GitHub Desktop.
Last question
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 Cylinder | |
def initialize(r,h) | |
@r = r | |
@h = h | |
end | |
def volume | |
pi * r * r * h | |
end | |
end | |
class Can < Cylinder | |
def initialize(r,h,price,title) | |
super(r,h) | |
@price = price | |
@title = title | |
end | |
attr_accessor :price | |
end | |
cans = [] | |
cans << Can.new 5,5,5,'beer' | |
cans << Can.new 5,5,5,'soda' | |
cans << Can.new 5,5,5,'water' | |
cans.max_by { |can| can.volume/can.price } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment