Skip to content

Instantly share code, notes, and snippets.

@gregory
Last active December 16, 2015 06:28
Show Gist options
  • Save gregory/5391286 to your computer and use it in GitHub Desktop.
Save gregory/5391286 to your computer and use it in GitHub Desktop.
jsut simpel example for POO
class Cirle < Form
attr_reader :rayon
def initializer(rayon)
@rayon = rayon
end
#Circle.area(20) => 200
def self.area(rayon)
Math.Pi * rayon**2
end
#Cicle.pring_area(20) => "Ma super surface est de: 200"
def self.pring_area(rayon)
puts "Ma super surface est de: #{self.area(rayon)}"
end
#Cicle.pring_area_with_instance(20) => "Ma super surface est de: 200"
def self.pring_area_with_instance(rayon)
mon_cirle = Circle.new(20)
puts "Ma super surface est de: #{mon_cirle.area}"
end
#mon_cercle = Circle.new(20); mon_cercle.rayon => 20; mon_cercle.area => 200
def area
Circle.area(self.reayon)
end
#mon_volume = Circle.new(20); mon_cercle.rayon => 20; mon_cercle.area => 200; mon_cercle.volume => 4000
def volume
4/3 * self.area * self.rayon
end
end
class Form
def color
end
def area
end
def volume
end
end
class Square < Forme
def self.area(length)
end
def area
end
def volume
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment