Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
class Point
attr_accessor :x,:y
def initialize(x=0, y=0)
self.x = x
self.y = y
end
def to_s
"Point at #{x},#{y}"
end
end
# When defining Circle class as the sub-class of the Point class:
class Circle < Point
attr_accessor :r
def initialize(x=0, y=0, r=0)
self.x = x
self.y = y
self.r = r
end
def to_s
"Circle at #{x},#{y} with radius #{r}"
end
end

View file

@ -0,0 +1,15 @@
# create a point
puts Point.new # => Point at 0,0
p = Point.new(1, 2)
puts p # => Point at 1,2
puts p.x # => 1
p.y += 1
puts p # => Point at 1,3
# create a circle
c = Circle.new(4,5,6)
# copy it
d = c.dup
d.r = 7.5
puts c # => Circle at 4,5 with radius 6
puts d # => Circle at 4,5 with radius 7.5