Skip to content

Instantly share code, notes, and snippets.

@onewland
Created May 16, 2011 22:09
Show Gist options
  • Save onewland/975489 to your computer and use it in GitHub Desktop.
Save onewland/975489 to your computer and use it in GitHub Desktop.
Last question
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