Skip to content

Instantly share code, notes, and snippets.

@begin29
Created February 7, 2017 19:54
Show Gist options
  • Save begin29/28e908b5d8c8e23003ea15d11406fed8 to your computer and use it in GitHub Desktop.
Save begin29/28e908b5d8c8e23003ea15d11406fed8 to your computer and use it in GitHub Desktop.
figure task from Denys
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
@begin29
Copy link
Author

begin29 commented Feb 7, 2017

def calculate_area
   puts "#{@color.to_s} ...
end

тут @color - виклик метода на пряму. Зроби, будь-ласка, через геттер. Тобто attr_reader та виклик як color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment