Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,73 @@
MyPoint := new Point(1, 8)
MyPoint.Print()
MyCircle := new Circle(4, 7, 9)
MyCircle2 := MyCircle.Copy()
MyCircle.SetX(2) ;Assignment method
MyCircle.y := 3 ;Direct assignment
MyCircle.Print()
MyCircle2.Print()
MyCircle.SetX(100), MyCircle.SetY(1000), MyCircle.r := 10000
MsgBox, % MyCircle.__Class
. "`n`nx:`t" MyCircle.GetX()
. "`ny:`t" MyCircle.y
. "`nr:`t" MyCircle.GetR()
return
class Point
{
Copy()
{
return this.Clone()
}
GetX()
{
return this.x
}
GetY()
{
return this.y
}
__New(x, y)
{
this.x := x
this.y := y
}
Print()
{
MsgBox, % this.__Class
. "`n`nx:`t" this.x
. "`ny:`t" this.y
}
SetX(aValue)
{
this.x := aValue
}
SetY(aValue)
{
this.y := aValue
}
}
class Circle extends Point
{
GetR()
{
return this.r
}
__New(x, y, r)
{
this.r := r
base.__New(x, y)
}
Print()
{
MsgBox, % this.__Class
. "`n`nx:`t" this.x
. "`ny:`t" this.y
. "`nr:`t" this.r
}
SetR(aValue)
{
this.r := aValue
}
}

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

View file

@ -1,22 +0,0 @@
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
class Circle
attr_accessor :x,:y,: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

@ -42,7 +42,7 @@ oo::class create Circle {
}
# No destructors: unneeded by these classes
set p [Point new 1.0 2.0]
set p [Point new 1.0 2.0]
set c [Circle new 3.0 4.0 5.0]
set cCopy [$c copy]
puts "$p is at ([$p x],[$p y])"