Created
February 7, 2017 19:54
-
-
Save begin29/28e908b5d8c8e23003ea15d11406fed8 to your computer and use it in GitHub Desktop.
figure task from Denys
This file contains hidden or 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 Figure | |
attr_reader :radius | |
def initialize(color,radius) | |
@color = color | |
@radius = radius | |
raise "first argument needs to be a string" unless color.class == String | |
raise "second argument needs to be a fixnum" unless radius.class == Fixnum | |
end | |
def calculate_area | |
puts "#{@color.to_s} #{self.class.to_s.downcase} has #{self.prepared_area.round(2).to_s} area}" | |
end | |
end | |
class Circle < Figure | |
def prepared_area | |
p radius**2 * Math::PI | |
end | |
end | |
class Square < Figure | |
def prepared_area | |
p radius**2 | |
end | |
end | |
c = Circle.new('blue', 10) | |
c.calculate_area | |
sq = Square.new('yellow', 12) | |
sq.calculate_area |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
тут
@color
- виклик метода на пряму. Зроби, будь-ласка, через геттер. Тобтоattr_reader
та виклик якcolor