Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
basic rubyish inheritance (no mixins yet)
- Loading branch information
Showing
3 changed files
with
122 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| puts "1..10" | ||
|
|
||
| class Point | ||
| @@tst = -1 | ||
| def initialize(x, y) | ||
| puts "ok #{ @@tst = @@tst + 2 } - Point.initialize called" | ||
| @x = x | ||
| @y = y | ||
| end | ||
|
|
||
| def x; @x ; end | ||
| def y; @y ; end | ||
|
|
||
| def theta; (@x * @x + @y * @y) ** 0.5; end | ||
| end | ||
|
|
||
| class Point3D < Point | ||
| def initialize(x, y, z) | ||
| puts "ok 2 - Point3D.initialize called" | ||
| super(x, y) | ||
| @z = z | ||
| end | ||
|
|
||
| def z; @z ; end | ||
|
|
||
| def theta; (@x * @x + @y * @y + @z * @z) ** 0.5; end | ||
| end | ||
|
|
||
| obj_2d = Point.new(10, 20) | ||
| obj_3d = Point3D.new(15, 25, 35) | ||
|
|
||
| puts "#{obj_2d.x == 10 ? 'ok' : 'nok'} 4 - 2d obj x" | ||
| puts "#{obj_2d.y == 20 ? 'ok' : 'nok'} 5 - 2d obj y" | ||
|
|
||
| t2 = obj_2d.theta | ||
| puts "#{t2 > 22 && t2 < 23 ? 'ok' : 'nok'} 6 - theta 2d (approx)" | ||
|
|
||
| puts "#{obj_3d.x == 15 ? 'ok' : 'nok'} 7 - 3d obj x" | ||
| puts "#{obj_3d.y == 25 ? 'ok' : 'nok'} 8 - 3d obj y" | ||
| puts "#{obj_3d.z == 35 ? 'ok' : 'nok'} 9 - 3d obj z" | ||
|
|
||
| t3 = obj_3d.theta | ||
| puts "#{t3 > 45 && t2 < 46 ? 'ok' : 'nok'} 10 - theta 3d (approx)" |